src/EventSubscriber/MenuBuilderSubscriber.php line 37
<?php/** This file is part of the Tabler-Bundle demo.* Copyright 2021 Kevin Papst - www.kevinpapst.de** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/namespace App\EventSubscriber;use KevinPapst\TablerBundle\Event\MenuEvent;use KevinPapst\TablerBundle\Model\MenuItemInterface;use KevinPapst\TablerBundle\Model\MenuItemModel;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;class MenuBuilderSubscriber implements EventSubscriberInterface{private $security;private $environment;public function __construct(AuthorizationCheckerInterface $security, string $environment){$this->security = $security;$this->environment = $environment;}public static function getSubscribedEvents(): array{return [MenuEvent::class => ['onSetupNavbar', 100],];}public function onSetupNavbar(MenuEvent $event): void{$event->addItem(new MenuItemModel('dashboard', 'dashboard', 'app_dashboard', [], 'fas fa-tachometer-alt'));if (!$this->security->isGranted('IS_AUTHENTICATED')) {$event->addItem(new MenuItemModel('login', 'login', 'app_login', [], 'fas fa-sign-in-alt'));}$Client = new MenuItemModel('Client', 'Clients', null, [],'fa fa-fw fa-address-book');$Client->addChild(new MenuItemModel('Client', 'Clients Manager', 'app_client_index', [], 'far fa-users'));$event->addItem($Client);$Cases = new MenuItemModel('case', 'Registre.Cases', null, [],'fa fa-fw fa-balance-scale');$Cases->addChild(new MenuItemModel('buttons', 'Cases', 'app_case_index', [], 'far fa-folder'));$Cases->addChild(new MenuItemModel('buttons', 'MyCases','app_case_index_with_locked',['lockedbyme'=>'true'],'far fa-folder-open'));$vertical = new MenuItemModel('navbar-vertical', '', null, []);$vertical->setDivider(true);$Cases->addChild($vertical);$Cases->setDivider(true);$Cases->addChild(new MenuItemModel('buttons', 'CreateNew','app_case_new',[],'far fa-plus-square'));$event->addItem($Cases);$Financial = new MenuItemModel('financial', 'Registre.Financial', null, [],'fa fa-fw fa-bank');$Financial->addChild(new MenuItemModel('buttons', 'incomes/expenses', 'app_income_expense_index', [], 'fa fa-fw fa-columns'));$event->addItem($Financial);$Deposit = new MenuItemModel('Deposit', 'Registre.Deposits', null, [],'fa fa-fw fa-money');$Deposit->addChild(new MenuItemModel('buttons', 'Deposits', 'app_deposit_index', [], 'fa fa-fw fa-usd'));$event->addItem($Deposit);if ($this->security->isGranted('ROLE_ADMIN')) {$users = new MenuItemModel('user', 'Users', null, [], 'fa fa-fw fa-users');$users->addChild(new MenuItemModel('buttons', 'Users', 'app_user_index', [], 'fa fa-fw fa-users'));$event->addItem($users);}$Report = new MenuItemModel('report', 'Report', null, [], 'fa fa-fw fa-report');$event->addItem($Report);$this->activateByRoute($event->getRequest()->get('_route'),$event->getItems());}/*** @param string $route* @param MenuItemInterface[] $items*/protected function activateByRoute(string $route, array $items): void{foreach ($items as $item) {if ($item->hasChildren()) {$this->activateByRoute($route, $item->getChildren());} elseif ($item->getRoute() == $route) {$item->setIsActive(true);}}}}