Example #1
0
 /**
  * @param Item $rootMenuItem
  * @return KnpItemInterface
  */
 protected function createMenuRoot(Item $rootMenuItem)
 {
     $menu = $this->factory->createItem('root');
     $menu->setChildrenAttribute('class', $rootMenuItem->getOption('attr')['class']);
     $menu->setChildrenAttribute('id', $rootMenuItem->getOption('attr')['id']);
     return $menu;
 }
 /**
  * @return Item
  */
 private function createRootItem()
 {
     $rootItem = new Item('account');
     $rootItem->setLabel($this->translator->trans('admin.welcome', array('%username%' => $this->tokenStorage->getToken()->getUsername()), 'FSiAdminSecurity'));
     $rootItem->setOptions(array('attr' => array('id' => 'account')));
     return $rootItem;
 }
 public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
 {
     $knpMenuItem->setUri('#');
     if ($adminMenuItem->hasOption('attr')) {
         $knpMenuItem->setAttributes($adminMenuItem->getOption('attr'));
     }
     if ($adminMenuItem->hasChildren()) {
         $knpMenuItem->setAttribute('dropdown', true);
     }
 }
 public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
 {
     if ($adminMenuItem instanceof ElementItem && $adminMenuItem->hasOption('elements')) {
         $routes = $knpMenuItem->getExtra('routes', array());
         /** @var Element $element */
         foreach ($adminMenuItem->getOption('elements') as $element) {
             $routes[] = array('route' => $element->getRoute(), 'parameters' => $element->getRouteParameters());
         }
         $knpMenuItem->setExtra('routes', $routes);
     }
 }
 private function cleanMenuLevel(MenuItem $menu)
 {
     if (!$menu->hasChildren()) {
         return;
     }
     foreach ($menu->getChildren() as $menuItem) {
         $this->cleanMenuLevel($menuItem);
         if (!$menuItem instanceof RoutableItem && !$menuItem->hasChildren()) {
             $menu->removeChild($menuItem->getName());
         }
     }
 }
 public function createLocaleMenu(MenuEvent $event)
 {
     if (count($this->locales) < 2) {
         return;
     }
     $language = new Item('admin-locale');
     $language->setLabel($this->translator->trans('admin.language.current', array('%locale%' => $this->getLanguageName()), 'FSiAdminBundle'));
     $language->setOptions(array('attr' => array('id' => 'language')));
     foreach ($this->locales as $locale) {
         $localeItem = new RoutableItem(sprintf('admin-locale.%s', $locale), 'fsi_admin_locale', array('_locale' => $locale, 'redirect_uri' => $this->requestStack->getMasterRequest()->getUri()));
         $localeItem->setLabel($this->getLanguageName($locale));
         if ($locale === $this->getCurrentLocale()) {
             $localeItem->setOptions(array('attr' => array('class' => 'active')));
         }
         $language->addChild($localeItem);
     }
     $event->getMenu()->addChild($language);
 }
Example #7
0
 private function populateMenu(Item $menu, array $configs)
 {
     foreach ($configs as $itemConfig) {
         $item = $this->buildSingleItem($itemConfig);
         if (null !== $item) {
             $options = array('attr' => array('class' => 'admin-element'));
             $options['elements'] = $this->buildItemElements($itemConfig);
             $item->setOptions($options);
         }
         if (null === $item) {
             if ($this->isSingleItem($itemConfig)) {
                 continue;
             }
             $item = new Item(key($itemConfig));
             $group = array_values($itemConfig);
             $this->populateMenu($item, $group[0]);
         }
         $menu->addChild($item);
     }
 }
 /**
  * @param \FSi\Bundle\AdminBundle\Event\MenuEvent $event
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $menu
  * @param \FSi\Bundle\AdminBundle\Menu\Item\ElementItem $childItem1
  * @param \FSi\Bundle\AdminBundle\Menu\Item\RoutableItem $childItem2
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $childItem3
  * @param \FSi\Bundle\AdminBundle\Menu\Item\RoutableItem $childItem31
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $childItem4
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $childItem41
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $childItem411
  */
 public function it_remove_empty_menus($event, $menu, $childItem1, $childItem2, $childItem3, $childItem31, $childItem4, $childItem41, $childItem411)
 {
     $event->getMenu()->willReturn($menu);
     $menu->hasChildren()->willReturn(true);
     $childItem3->getName()->willReturn('item3');
     $childItem3->hasChildren()->willReturn(true);
     $childItem3->getChildren()->willReturn([$childItem31]);
     $childItem4->getName()->willReturn('item4');
     $childItem4->hasChildren()->willReturn(false);
     //after cleanup of item41
     $childItem4->getChildren()->willReturn([$childItem41]);
     $menu->removeChild('item4')->shouldBeCalled();
     $childItem41->getName()->willReturn('item41');
     $childItem41->hasChildren()->willReturn(false);
     //after cleanup of item411
     $childItem41->getChildren()->willReturn([$childItem411]);
     $childItem411->getName()->willReturn('item411');
     $childItem411->hasChildren()->willReturn(false);
     $menu->getChildren()->willReturn([$childItem1, $childItem2, $childItem3, $childItem4]);
     $this->cleanUpMenu($event);
 }
Example #9
0
 /**
  * @param \Knp\Menu\FactoryInterface $factory
  * @param \Knp\Menu\ItemInterface $knpRootItem
  * @param \Knp\Menu\ItemInterface $knpFirstItem
  * @param \Knp\Menu\ItemInterface $knpSecondItem
  * @param \Knp\Menu\ItemInterface $knpChildOfSecondItem
  * @param \FSi\Bundle\AdminBundle\Menu\KnpMenu\ItemDecorator $itemDecorator
  * @param \FSi\Bundle\AdminBundle\Menu\Builder\Builder $builder
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $rootItem
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $firstItem
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $secondItem
  * @param \FSi\Bundle\AdminBundle\Menu\Item\Item $childOfSecondItem
  */
 function it_builds_knp_menu_and_decorates_items($factory, $knpRootItem, $knpFirstItem, $knpSecondItem, $knpChildOfSecondItem, $itemDecorator, $builder, $rootItem, $firstItem, $secondItem, $childOfSecondItem)
 {
     $builder->buildMenu()->willReturn($rootItem);
     $firstItem->getName()->willReturn('first item');
     $firstItem->hasChildren()->willReturn(false);
     $secondItem->getName()->willReturn('second item');
     $secondItem->hasChildren()->willReturn(true);
     $childOfSecondItem->getName()->willReturn('child of second item');
     $childOfSecondItem->hasChildren()->willReturn(false);
     $rootItem->getChildren()->willReturn(array($firstItem, $secondItem));
     $secondItem->getChildren()->willReturn(array($childOfSecondItem));
     $rootItem->getOption('attr')->willReturn(array('id' => null, 'class' => 'some class'));
     $factory->createItem('root')->willReturn($knpRootItem);
     $knpRootItem->addChild('first item', array())->willReturn($knpFirstItem);
     $knpRootItem->addChild('second item', array())->willReturn($knpSecondItem);
     $knpSecondItem->addChild('child of second item', array())->willReturn($knpChildOfSecondItem);
     $knpRootItem->setChildrenAttribute('id', null)->shouldBeCalled();
     $knpRootItem->setChildrenAttribute('class', 'some class')->shouldBeCalled();
     $itemDecorator->decorate($knpFirstItem, $firstItem)->shouldBeCalled();
     $itemDecorator->decorate($knpSecondItem, $secondItem)->shouldBeCalled();
     $itemDecorator->decorate($knpChildOfSecondItem, $childOfSecondItem)->shouldBeCalled();
     $this->createMenu($builder);
 }
Example #10
0
 public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
 {
     if ($adminMenuItem instanceof RoutableItem && $adminMenuItem->getRoute()) {
         $knpMenuItem->setUri($this->router->generate($adminMenuItem->getRoute(), $adminMenuItem->getRouteParameters()));
         $routes = $knpMenuItem->getExtra('routes', array());
         $routes[] = array('route' => $adminMenuItem->getRoute(), 'parameters' => $adminMenuItem->getRouteParameters());
         $knpMenuItem->setExtra('routes', $routes);
     }
 }
 private function populateTranslationLocaleMenu(Item $menu)
 {
     $requestParameters = $this->getRequestParameters();
     $route = $this->request->get('_route');
     $languageBundle = Intl::getLanguageBundle();
     if (isset($requestParameters['redirect_uri'])) {
         $redirectRequest = $this->createRedirectRequest($requestParameters['redirect_uri']);
     }
     foreach ($this->localeManager->getLocales() as $locale) {
         $requestParameters['locale'] = $locale;
         if (isset($redirectRequest)) {
             try {
                 $requestParameters['redirect_uri'] = $this->generateRequestUriForLocale($redirectRequest, $locale);
             } catch (ResourceNotFoundException $e) {
             }
         }
         $localeItem = new RoutableItem(sprintf('translation-locale.%s', $locale), $route, $requestParameters);
         $localeItem->setLabel($languageBundle->getLanguageName($locale, null, $this->request->getLocale()));
         $menu->addChild($localeItem);
     }
 }
Example #12
0
 /**
  * @param Item $item
  */
 public function addChild(Item $item)
 {
     $this->children[$item->getName()] = $item;
 }
Example #13
0
 public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
 {
     if ($adminMenuItem->getLabel()) {
         $knpMenuItem->setLabel($adminMenuItem->getLabel());
     }
 }