示例#1
0
 public function createMainMenu()
 {
     $menu = $this->factory->createItem('root')->setChildrenAttribute('class', 'nav navbar-nav');
     $menu->addChild('menu.start', ['route' => 'app_index']);
     $this->createSceneMenu($menu);
     return $menu;
 }
 public function load($data)
 {
     if (!$this->supports($data)) {
         throw new \InvalidArgumentException(sprintf('NodeLoader can only handle data implementing NodeInterface, "%s" given.', is_object($data) ? get_class($data) : gettype($data)));
     }
     $event = new CreateMenuItemFromNodeEvent($data);
     $this->dispatcher->dispatch(Events::CREATE_ITEM_FROM_NODE, $event);
     if ($event->isSkipNode()) {
         if ($data instanceof Menu) {
             // create an empty menu root to avoid the knp menu from failing.
             return $this->menuFactory->createItem('');
         }
         return;
     }
     $item = $event->getItem() ?: $this->menuFactory->createItem($data->getName(), $data->getOptions());
     if (empty($item)) {
         return;
     }
     if ($event->isSkipChildren()) {
         return $item;
     }
     foreach ($data->getChildren() as $childNode) {
         if ($childNode instanceof NodeInterface) {
             $child = $this->load($childNode);
             if (!empty($child)) {
                 $item->addChild($child);
             }
         }
     }
     return $item;
 }
示例#3
0
 /**
  * Returns root item
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function getRoot()
 {
     if ($this->root === null) {
         $this->root = $this->menuFactory->createItem($this->getName());
     }
     return $this->root;
 }
示例#4
0
 /**
  * Returns the external menu
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function getExternal()
 {
     $menu = $this->factory->createItem('external');
     $menu->addChild('GitHub', ['uri' => 'https://github.com/tomaskadlec/lunch_guy', 'attributes' => ['icon' => 'fa-github', 'no_label' => true]]);
     $menu->addChild('Slack', ['uri' => 'https://ictfit.slack.com/messages/obed/', 'attributes' => ['icon' => 'fa-slack', 'no_label' => true]]);
     return $menu;
 }
示例#5
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;
 }
 /**
  * Retrieves the menu based on the group options.
  *
  * @param string $name
  * @param array  $options
  *
  * @return \Knp\Menu\ItemInterface
  *
  * @throws \InvalidArgumentException if the menu does not exists
  */
 public function get($name, array $options = array())
 {
     $group = $options['group'];
     $menuItem = $this->menuFactory->createItem($options['name'], array('label' => $group['label']));
     foreach ($group['items'] as $item) {
         if (isset($item['admin']) && !empty($item['admin'])) {
             $admin = $this->pool->getInstance($item['admin']);
             // skip menu item if no `list` url is available or user doesn't have the LIST access rights
             if (!$admin->hasRoute('list') || !$admin->isGranted('LIST')) {
                 continue;
             }
             $label = $admin->getLabel();
             $options = $admin->generateMenuUrl('list');
             $options['extras'] = array('translation_domain' => $admin->getTranslationDomain(), 'admin' => $admin);
         } else {
             $label = $item['label'];
             $options = array('route' => $item['route'], 'routeParameters' => $item['route_params'], 'extras' => array('translation_domain' => $group['label_catalogue']));
         }
         $menuItem->addChild($label, $options);
     }
     if (false === $menuItem->hasChildren()) {
         $menuItem->setDisplay(false);
     }
     return $menuItem;
 }
 /**
  * Build menu.
  *
  * @param  string        $alias
  * @param  array         $options
  * @return ItemInterface
  */
 public function get($alias, array $options = [])
 {
     $this->assertAlias($alias);
     if (!array_key_exists($alias, $this->menus)) {
         if ($this->cache && $this->cache->contains($alias)) {
             $menuData = $this->cache->fetch($alias);
             $this->menus[$alias] = $this->factory->createFromArray($menuData);
         } else {
             $menu = $this->factory->createItem($alias);
             /** @var BuilderInterface $builder */
             // try to find builder for the specified menu alias
             if (array_key_exists($alias, $this->builders)) {
                 foreach ($this->builders[$alias] as $builder) {
                     $builder->build($menu, $options, $alias);
                 }
             }
             // In any case we must run common builder
             if (array_key_exists(self::COMMON_BUILDER_ALIAS, $this->builders)) {
                 foreach ($this->builders[self::COMMON_BUILDER_ALIAS] as $builder) {
                     $builder->build($menu, $options, $alias);
                 }
             }
             $this->menus[$alias] = $menu;
             $this->eventDispatcher->dispatch(ConfigureMenuEvent::getEventName($alias), new ConfigureMenuEvent($this->factory, $menu));
             $this->sort($menu);
             if ($this->cache) {
                 $this->cache->save($alias, $menu->toArray());
             }
         }
     }
     return $this->menus[$alias];
 }
示例#8
0
 /**
  * Creates the header menu
  *
  * @param FactoryInterface $factory
  * @param array            $options
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function mainMenu(FactoryInterface $factory, array $options)
 {
     $isFooter = array_key_exists('is_footer', $options) ? $options['is_footer'] : false;
     $shopCategories = $this->container->get('sonata.classification.manager.category')->getRootCategory('product_catalog');
     $menuOptions = array_merge($options, array('childrenAttributes' => array('class' => 'nav nav-pills')));
     $menu = $factory->createItem('main', $menuOptions);
     $shopMenuParams = array('route' => 'sonata_catalog_index');
     if (count($shopCategories->hasChildren()) > 0 && !$isFooter) {
         $shopMenuParams = array_merge($shopMenuParams, array('attributes' => array('class' => 'dropdown'), 'childrenAttributes' => array('class' => 'dropdown-menu'), 'linkAttributes' => array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'data-target' => '#'), 'label' => 'Products <b class="caret caret-menu"></b>', 'extras' => array('safe_label' => true)));
     }
     if ($isFooter) {
         $shopMenuParams = array_merge($shopMenuParams, array('attributes' => array('class' => 'span2'), "childrenAttributes" => array('class' => 'nav')));
     }
     $shop = $menu->addChild('Shop', $shopMenuParams);
     $menu->addChild('News', array('route' => 'sonata_news_home'));
     foreach ($shopCategories->getChildren() as $category) {
         $shop->addChild($category->getName(), array('route' => 'sonata_catalog_category', 'routeParameters' => array('category_id' => $category->getId(), 'category_slug' => $category->getSlug())));
     }
     $dropdownExtrasOptions = $isFooter ? array('uri' => "#", 'attributes' => array('class' => 'span2'), 'childrenAttributes' => array('class' => 'nav')) : array('uri' => "#", 'attributes' => array('class' => 'dropdown'), 'childrenAttributes' => array('class' => 'dropdown-menu'), 'linkAttributes' => array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'data-target' => '#'), 'label' => 'Solutions <b class="caret caret-menu"></b>', 'extras' => array('safe_label' => true));
     $extras = $factory->createItem('Discover', $dropdownExtrasOptions);
     $extras->addChild('Bundles', array('route' => 'page_slug', 'routeParameters' => array('path' => '/bundles')));
     $extras->addChild('Api', array('route' => 'page_slug', 'routeParameters' => array('path' => '/api-landing')));
     $extras->addChild('Gallery', array('route' => 'sonata_media_gallery_index'));
     $extras->addChild('Media & SEO', array('route' => 'sonata_demo_media'));
     $menu->addChild($extras);
     $menu->addChild('Admin', array('route' => 'page_slug', 'routeParameters' => array('path' => '/user')));
     if ($isFooter) {
         $menu->addChild('Legal notes', array('route' => 'page_slug', 'routeParameters' => array('path' => '/legal-notes')));
     }
     return $menu;
 }
 /**
  * @return ItemInterface
  */
 public function createMainMenu()
 {
     $menu = $this->factory->createItem('root', ['childrenAttributes' => ['class' => 'nav-pills', 'role' => 'tablist']]);
     $menu->addChild('Recepten', ['route' => 'recipe_index']);
     $menu->addChild('Brouwsels', ['route' => 'batch_index']);
     return $menu;
 }
示例#10
0
 /**
  * Breadcrumbs
  *
  * @param Request $request
  *
  * @return mixed
  */
 public function createBreadcrumbsMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $menu->setUri($request->getRequestUri());
     $menu->addChild($this->translator->trans('Главная'), array('route' => 'homepage'));
     return $menu;
 }
 /**
  * Builds the menu from a given route
  *
  * @param null|string $fromRoute
  * @param array $options
  *
  * @return ItemInterface
  */
 public function buildMenu($fromRoute = null, array $options = [])
 {
     $root = $this->factory->createItem("root");
     // prepare menu for bootstrap
     $this->appendNodes($root, $this->pageTreeModel->getPageTree($fromRoute), $options);
     return $root;
 }
 /**
  * Navbar Menu
  * 
  * @param array $options
  * @return ItemInterface
  */
 public function createPrimaryMenu(array $options)
 {
     $menu = $this->factory->createItem('root');
     $this->eventDispatcher->dispatch(WebsiteEvents::PRIMARY_MENU_INIT, new PrimaryMenuEvent($menu, $this->factory));
     $this->reorderMenuItems($menu);
     return $menu;
 }
 public function createPlanMenu()
 {
     $menu = $this->factory->createItem('root');
     $this->event_dispatcher->dispatch(MenuPlanEvent::BEFORE_GENERATION, new MenuPlanEvent($this->factory, $menu));
     $this->generatePageMenu($menu);
     $this->event_dispatcher->dispatch(MenuPlanEvent::AFTER_GENERATION, new MenuPlanEvent($this->factory, $menu));
     return $menu;
 }
 /**
  * Menu builder
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function createMenu()
 {
     $menu = $this->factory->createItem('menu');
     $menu->addChild('home', ['label' => 'nav.admin_panel', 'route' => 'admin_homepage']);
     $menu->addChild('manage_events', ['label' => 'nav.manage_events', 'route' => 'admin_registration_events_list']);
     $menu->addChild('logout', ['route' => 'admin_logout', 'label' => 'admin.logout']);
     return $menu;
 }
示例#15
0
 public function createMainMenu()
 {
     $this->menu = $this->factory->createItem('root');
     $this->addDashboard();
     $this->eventDispatcher->dispatch(self::MENU_BUILD_EVENT, new Event($this->menu));
     $this->addConfiguration();
     return $this->menu;
 }
 /**
  * @return ItemInterface
  */
 public function createMainMenu()
 {
     $menu = $this->factory->createItem('root');
     $menu->setChildrenAttribute('class', 'nav');
     $this->eventDispatcher->dispatch(ConfigureMenuEvent::EVENT_NAME, new ConfigureMenuEvent($this->getFactory(), $menu));
     $this->reorderMenuItems($menu);
     return $menu;
 }
 public function createMenu(array $items = [], $options = [])
 {
     $menu = $this->factory->createItem('root')->setChildrenAttributes(['class' => isset($options['class']) ? $options['class'] : 'nav navbar-nav']);
     foreach ($items as $key => $menuItemConfig) {
         $menu->addChild('main-menu-item-' . $key, ['route' => $menuItemConfig['route'], 'routeParameters' => isset($menuItemConfig['route_parameters']) ? $menuItemConfig['route_parameters'] : [], 'label' => $menuItemConfig['label']]);
     }
     return $menu;
 }
示例#18
0
 public function createProfileMenu(RequestStack $requestStack)
 {
     $menu = $this->factory->createItem('profile');
     $menu->addChild('profile_menu.edit_profile', array('route' => 'profile'));
     $menu->addChild('profile_menu.change_password', array('route' => 'profile_change_password'));
     $menu->addChild('profile_menu.manage_administrations', array('route' => 'manage_administrations'));
     $menu->addChild('profile_menu.logout', array('route' => 'logout'));
     return $menu;
 }
示例#19
0
 /**
  * @param RequestStack $requestStack
  *
  * @return ItemInterface
  */
 public function createMainMenu(RequestStack $requestStack)
 {
     $menu = $this->factory->createItem('root');
     $menu->setChildrenAttribute('class', 'nav navbar-nav navbar-left');
     $menu->addChild('Product list', ['route' => 'list_products']);
     $menu->addChild('My basket', ['route' => 'show_basket']);
     $menu->addChild('My settings', ['route' => 'edit_settings']);
     return $menu;
 }
 /**
  * @param Request $request
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function createTrainingMenu(Request $request)
 {
     $menu = $this->factory->createItem('training');
     $trainingMenu = $menu->addChild('training', ['label' => $this->translator->trans('training.menu', [], 'training')]);
     foreach ($this->certificationManager->getCertifications() as $certificationName => $certificationLabel) {
         $trainingMenu->addChild($certificationName, ['route' => 'certification_guidelines', 'routeParameters' => ['name' => $certificationName], 'label' => $certificationLabel]);
     }
     return $menu;
 }
示例#21
0
 /**
  * @return MenuItem
  */
 public function getAffixMenu()
 {
     $menu = $this->findFirstLevelActive($this->menu);
     if (!$menu) {
         $menu = $this->factory->createItem('root', array('childrenAttributes' => array('class' => 'nav nav-sidebar')));
     }
     $menu->setChildrenAttributes(array('class' => 'nav nav-sidebar'));
     return $menu;
 }
示例#22
0
 /**
  * Creates main menu.
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function createMainMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $menu->setCurrentUri($request->getRequestUri());
     $menu->addChild('Home', array('route' => 'home'));
     $menu->addChild('Menu item 1', array('uri' => '#'));
     $menu->addChild('Menu item 2', array('uri' => '#'));
     return $menu;
 }
示例#23
0
 /**
  * @return ItemInterface
  */
 public function createMainMenu()
 {
     $menu = $this->factory->createItem('root')->setChildrenAttribute('class', 'nav navbar-nav');
     foreach ($this->elementManager->getElements() as $element) {
         $name = $element->getId();
         $menu->addChild(sprintf('front.menu.%s', $name), ['route' => 'crud_list', 'routeParameters' => ['elementName' => $name]]);
     }
     return $menu;
 }
示例#24
0
文件: Builder.php 项目: octava/cms
 /**
  * Builds sidebar menu.
  *
  * @return ItemInterface
  */
 public function createSidebarMenu()
 {
     $menu = $this->factory->createItem('root', ['extras' => ['request' => $this->requestStack->getMasterRequest()]]);
     $tree = $this->adminMenuManager->getTree();
     $this->generateMenu($menu, $tree);
     $event = new ConfigureMenuEvent($this->factory, $menu);
     $this->eventDispatcher->dispatch(ConfigureMenuEvent::SIDEBAR, $event);
     return $event->getMenu();
 }
示例#25
0
 public function createMainMenu(Request $request)
 {
     $menu = $this->_factory->createItem('root');
     $menu->setAttribute("currentClass", "active");
     //            "options" => array(
     //        "currentClass" => "active",
     //        "ancestorClass" => "active",
     //    )
     //        <li class="bigfish-nav-title">{{ parameter("client").name }}</li>
     if (isset($this->client["name"])) {
         $menu->addChild("_client_name", array("label" => $this->client["name"]))->setAttribute('class', 'bigfish-nav-title');
     }
     $currentLanguage = $this->languageManager->getCulture();
     $languageMenu = $menu->addChild($currentLanguage, array("uri" => "#", "label" => Locale::getDisplayLanguage($currentLanguage), "extras" => array("icon" => "glyphicon glyphicon-triangle-bottom")))->setAttribute('class', 'language');
     foreach ($this->languageManager->getLanguages() as $language) {
         if ($currentLanguage != $language) {
             $routeParams = $this->request->attributes->get("_route_params");
             $routeParams["language"] = $language;
             $route = $this->request->attributes->get("_route");
             $languageMenu->addChild($language, array("route" => $route, "routeParameters" => $routeParams, "label" => Locale::getDisplayLanguage($language)));
         }
     }
     //        {% for lang in getLanguages() %}
     //        {% if lang != app.request.get("language") %}
     //        {% set routeParams = routeParams | merge({"language" : lang}) %}
     //        <li><a href="{{ path(app.request.attributes.get("_route"), routeParams) }}">{{ lang }}</a></li>
     //							{% endif %}
     //						{% endfor %}
     //        <li class="language">
     //									<a href="#">Nederlands<span class="glyphicon glyphicon-triangle-bottom"></span></a>
     //									<ul>
     //										<li><a href="#">Duits</a></li>
     //										<li><a href="#">Engels</a></li>
     //										<li><a href="#">Frans</a></li>
     //									</ul>
     //								</li>
     //        exit;
     $menu->addChild("bigfish.menu.edit.label")->setAttribute('class', 'bigfish-nav-title');
     $this->_eventDispatcher->dispatch(ConfigureMenuEvent::CONFIGURE, new ConfigureMenuEvent($this->_factory, $menu));
     if (count($this->landingPages) > 0) {
         $lossePaginas = $menu->addChild("bigfish.landing.pages", array("uri" => "#", "extras" => array("icon" => "glyphicon glyphicon-pencil")));
         foreach ($this->landingPages as $key => $landingPage) {
             if (isset($landingPage["label"])) {
                 if (isset($landingPage["uri"])) {
                     $lossePaginas->addChild("item_" . $key, array("uri" => $landingPage["uri"], "label" => $landingPage["label"]));
                 }
                 if (isset($landingPage["route"])) {
                     $routeParams = isset($landingPage["routeParameters"]) ? $landingPage["routeParameters"] : array();
                     $lossePaginas->addChild("item_" . $key, array("route" => $landingPage["route"], "routeParameters" => $routeParams, "label" => $landingPage["label"]));
                 }
             }
         }
     }
     $menu->addChild('Gebruikers', array('route' => 'user_index', "extras" => array("icon" => "glyphicon glyphicon-user")));
     return $menu;
 }
示例#26
0
 public function createMainMenu(Request $request)
 {
     $root = $this->buildMainMenu($request, $this->factory->createItem('root', ['childrenAttributes' => []]));
     $menuIterator = new RecursiveIteratorIterator(new RecursiveItemIterator(new ArrayIterator([$root])), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($menuIterator as $item) {
         /** @var $item ItemInterface */
         $item->setAttribute('data-name', $item->getName());
     }
     return $root;
 }
示例#27
0
 /**
  * Creates the admin sidebar menu.
  *
  * @return ItemInterface A ItemInterface instance
  */
 public function createSidebarMenu()
 {
     $menu = $this->factory->createItem('sidebar', ['childrenAttributes' => ['id' => 'sidebar-menu', 'class' => 'sidebar-nav nav']]);
     $menu->addChild('dashboard', array('label' => 'Dashboard', 'route' => 'admin'));
     if ($this->securityChecker->isGranted('SUPERADMIN')) {
         $menu->addChild('adminuser', array('label' => 'Administradores', 'route' => 'admin_adminuser_list'))->setExtra('routes', array(array('pattern' => '/adminuser/')));
     }
     $this->dispatcher->dispatch(AdminMenuBuilderEvent::SIDEBAR, new AdminMenuBuilderEvent($this->factory, $menu, $this->securityChecker));
     return $menu;
 }
示例#28
0
 public function createMainMenu(Request $request)
 {
     $resources = $this->objectManager->getRepository("BigfishResourceBundle:Resource")->getMenu($request->getLocale());
     $items = $this->buildTree($resources);
     $menu = $this->_factory->createItem("root");
     foreach ($items as $resource) {
         $menu->addChild($this->fromArray($resource));
     }
     return $menu;
 }
示例#29
0
 /**
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 public function createMainMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $this->addRootMenuItems($menu);
     $admin = $this->factory->createItem('menu.admin.admin', array('extras' => array('icon' => 'icon-option')));
     $this->addAdminMenuItems($admin);
     $admin->setDisplay($admin->hasChildren());
     $menu->addChild($admin);
     $menu->setCurrentUri($request->getRequestUri());
     return $menu;
 }
 /**
  * {@inheritdoc}
  */
 public function get($name, array $options = [])
 {
     if (!$this->has($name, $options)) {
         throw new \InvalidArgumentException(sprintf('The menu "%s" is not defined.', $name));
     }
     if (!isset($this->menus[$name])) {
         $this->menus[$name] = $this->factory->createItem($name);
     }
     $this->eventDispatcher->dispatch(ConfigureMenuEvent::CONFIGURE, new ConfigureMenuEvent($this->factory, $this->menus[$name]));
     return $this->menus[$name];
 }