Пример #1
0
 public function onMenu(MenuEvent $event)
 {
     $menu = $event->getMenu();
     foreach ($menu->getChildren() as $child) {
         /** @var $child ItemInterface */
         if ($this->permissionCheck) {
             $role = $this->menu[$child->getName()]['role'];
             if (!$this->authorizationChecker->isGranted($role)) {
                 $child->setDisplay(false);
             }
         }
         $this->addClass($child);
         $this->addCurrent($child);
     }
 }
Пример #2
0
 public function getMenu()
 {
     $menuList = $this->factory->createItem($this->name);
     foreach ($this->menu as $name => $menuItem) {
         if ($this->securityContext->isGranted($menuItem['role'])) {
             $menu = $this->factory->createItem($name, array('route' => $menuItem['route']));
             $menu->setLabel($menuItem['label']);
             if (isset($menuItem['translationDomain'])) {
                 $menu->setLabelAttribute('translationDomain', $menuItem['translationDomain']);
             }
             $menuList->addChild($menu);
         }
     }
     $event = new MenuEvent();
     $event->setMenu($menuList);
     $this->dispatcher->dispatch($this->name, $event);
     return $event->getMenu();
 }