Ejemplo n.º 1
0
 /**
  * Build the menu
  *
  * @param Content $content
  *
  * @return \Knp\Menu\MenuItem
  */
 public function build(Content $content)
 {
     $menu = null;
     if (count($this->locales) > 1) {
         $factory = new MenuFactory();
         $menu = $factory->createItem('ContentMenu', $this->locales);
         $menu->addChild('default', ['uri' => $this->router->generate('opifer.cms.content.edit', ['id' => $content->getId() ? $content->getId() : 0, 'locale' => null]), 'label' => $this->translator->trans('Default')]);
         foreach ($this->locales as $plocale) {
             if ($plocale === $this->defaultLocale) {
                 continue;
             }
             $menu->addChild($plocale, ['uri' => $this->router->generate('opifer.cms.content.edit', ['id' => $content->getId() ? $content->getId() : 0, 'locale' => $plocale]), 'label' => $this->translator->trans($plocale)]);
         }
         foreach ($menu->getChildren() as $menuChild) {
             if ($menuChild->getName() == $locale) {
                 $menuChild->setCurrent(true);
             }
             if ($menuChild->getName() == 'default' && $locale == null) {
                 $menuChild->setCurrent(true);
             }
         }
     }
     return $menu;
 }