Use this file to discover all available pages before exploring further.
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.
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;}
Create a class in your src/ directory and implement MenuPermissionCheckerInterface.
src/Service/RoleMenuPermissionChecker.php
<?phpdeclare(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.
The label shown in the dashboard dropdown can be set in two ways:
Attribute (recommended)
Class constant
use Nowo\DashboardMenuBundle\Attribute\PermissionCheckerLabel;#[PermissionCheckerLabel('By role')]final class RoleMenuPermissionChecker implements MenuPermissionCheckerInterface{ // ...}
final class RoleMenuPermissionChecker implements MenuPermissionCheckerInterface{ public const string DASHBOARD_LABEL = 'By role'; // ...}
If neither is set, the service id (typically the fully-qualified class name) is used as the label.
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.