Skip to main content
By default the bundle uses AllowAllMenuPermissionChecker, which makes every item visible. To control item visibility — by Symfony role, feature flag, subscription, or any other rule — implement MenuPermissionCheckerInterface.

The interface

namespace Nowo\DashboardMenuBundle\Service;

use Nowo\DashboardMenuBundle\Entity\MenuItem;

interface MenuPermissionCheckerInterface
{
    /**
     * Whether the given menu item should be visible in the current context.
     *
     * @param mixed $context Optional context (e.g. current user, request)
     */
    public function canView(MenuItem $item, mixed $context = null): bool;
}

Implementing a checker

1

Create the class

Create a class in your src/ directory and implement MenuPermissionCheckerInterface.
src/Service/RoleMenuPermissionChecker.php
<?php

declare(strict_types=1);

namespace App\Service;

use Nowo\DashboardMenuBundle\Attribute\PermissionCheckerLabel;
use Nowo\DashboardMenuBundle\Entity\MenuItem;
use Nowo\DashboardMenuBundle\Service\MenuPermissionCheckerInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

#[PermissionCheckerLabel('By role')]
final class RoleMenuPermissionChecker implements MenuPermissionCheckerInterface
{
    public function __construct(
        private readonly AuthorizationCheckerInterface $authorizationChecker,
    ) {
    }

    public function canView(MenuItem $item, mixed $context = null): bool
    {
        if ($item->getPermissionKey() === null) {
            return true;
        }

        return $this->authorizationChecker->isGranted(
            $item->getPermissionKey(),
            $context
        );
    }
}
2

Done — no services.yaml tag needed

Any service whose class implements MenuPermissionCheckerInterface is automatically discovered and added to the dashboard Permission checker dropdown. Symfony’s default service discovery (resource: '../src/') picks it up without any extra configuration.

Setting a dashboard label

The label shown in the dashboard dropdown can be set in two ways: If neither is set, the service id (typically the fully-qualified class name) is used as the label.

Ordering and labelling via config

Use permission_checker_choices to control the order of checkers in the dropdown, or to override their labels:
nowo_dashboard_menu:
    permission_checker_choices:
        - Nowo\DashboardMenuBundle\Service\AllowAllMenuPermissionChecker
        - App\Service\RoleMenuPermissionChecker

Assigning a checker to a menu

Checkers are assigned per menu in the dashboard. Open the configuration panel (gear icon) for any menu and choose a checker from the Permission checker dropdown. Leave it unset to use the default allow-all behaviour.

How pruning works

When a checker hides an item, the bundle also removes any parent that has no visible children. This means:
  • A section (group header) with all children hidden is automatically removed.
  • A link with all children hidden keeps itself but loses the subtree.
This ensures the rendered tree never shows empty section labels or orphaned parents.

Built-in checkers

ClassBehaviour
AllowAllMenuPermissionCheckerAlways returns true. Default when no checker is assigned.
PermissionKeyAwareMenuPermissionCheckerItems without a permissionKey are visible; items with any key are hidden. Use as a structural reference or extend it for your own logic.