本文整理汇总了PHP中Knp\Menu\FactoryInterface::createItem方法的典型用法代码示例。如果您正苦于以下问题:PHP FactoryInterface::createItem方法的具体用法?PHP FactoryInterface::createItem怎么用?PHP FactoryInterface::createItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Knp\Menu\FactoryInterface
的用法示例。
在下文中一共展示了FactoryInterface::createItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createMainMenu
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;
}
示例2: load
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: getRoot
/**
* 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: getExternal
/**
* 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: createMenuRoot
/**
* @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;
}
示例6: get
/**
* 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;
}
示例7: get
/**
* 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: mainMenu
/**
* 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;
}
示例9: createMainMenu
/**
* @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: createBreadcrumbsMenu
/**
* 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;
}
示例11: buildMenu
/**
* 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;
}
示例12: createPrimaryMenu
/**
* 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;
}
示例13: createPlanMenu
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;
}
示例14: createMenu
/**
* 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: createMainMenu
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;
}