当前位置: 首页>>代码示例>>PHP>>正文


PHP ItemInterface::getChildren方法代码示例

本文整理汇总了PHP中Knp\Menu\ItemInterface::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface::getChildren方法的具体用法?PHP ItemInterface::getChildren怎么用?PHP ItemInterface::getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Knp\Menu\ItemInterface的用法示例。


在下文中一共展示了ItemInterface::getChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sort

 /**
  * Reorder menu based on position attribute
  *
  * @param ItemInterface $menu
  */
 protected function sort(ItemInterface $menu)
 {
     if ($menu->hasChildren() && $menu->getDisplayChildren()) {
         $orderedChildren = [];
         $unorderedChildren = [];
         $hasOrdering = false;
         $children = $menu->getChildren();
         foreach ($children as &$child) {
             if ($child->hasChildren() && $child->getDisplayChildren()) {
                 $this->sort($child);
             }
             $position = $child->getExtra('position');
             if ($position !== null) {
                 $orderedChildren[$child->getName()] = (int) $position;
                 $hasOrdering = true;
             } else {
                 $unorderedChildren[] = $child->getName();
             }
         }
         if ($hasOrdering) {
             asort($orderedChildren);
             $menu->reorderChildren(array_merge(array_keys($orderedChildren), $unorderedChildren));
         }
     }
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:30,代码来源:BuilderChainProvider.php

示例2: removeFactory

 /**
  * Рекурсивный метод для удаления фабрики, что позволяет кешировать объект меню.
  *
  * @param ItemInterface $menu
  */
 protected function removeFactory(ItemInterface $menu)
 {
     $menu->setFactory(new DummyFactory());
     foreach ($menu->getChildren() as $subMenu) {
         $this->removeFactory($subMenu);
     }
 }
开发者ID:smart-core,项目名称:module-unicat,代码行数:12,代码来源:TaxonMenu.php

示例3: flattenMenuItems

 /**
  * Get a flattened array containing references to all of the items
  *
  * @param ItemInterface $item   The menu item
  * @param bool          $isTop  Is the initial menu item starting at the top-level?
  * @return array
  */
 public static function flattenMenuItems(ItemInterface $item, $isTop = true)
 {
     $arr = $isTop ? [] : [$item];
     foreach ($item->getChildren() as $child) {
         $arr = array_merge($arr, self::flattenMenuItems($child, false));
     }
     return $arr;
 }
开发者ID:igorvbelousov,项目名称:toc,代码行数:15,代码来源:TOCTestUtils.php

示例4: reorderMenu

 /**
  * Reorder the menu
  *
  * @param \Knp\Menu\ItemInterface $menu
  *
  * @return MenuItem
  */
 private function reorderMenu($menu)
 {
     $menuItems = $menu->getChildren();
     usort($menuItems, array($this, 'menuSort'));
     $newMenuOrder = array();
     foreach ($menuItems as $menuItem) {
         $newMenuOrder[] = $menuItem->getName();
     }
     $menu->reorderChildren($newMenuOrder);
     return $menu;
 }
开发者ID:NaszvadiG,项目名称:Jumph,代码行数:18,代码来源:Builder.php

示例5: convertChildren

 /**
  * Convert Menu children to be a Bootstrap menu.
  *
  * The options array expect a key "automenu"
  * set to a string of possibleNavs
  *
  * Additional options may be specified and code tightened.
  *
  * @param ItemInterface $item
  * @param array         $options
  */
 public function convertChildren(ItemInterface $item, array $options)
 {
     foreach ($item->getChildren() as $child) {
         $autoChildOptions = $this->getChildOptions($child, $options);
         $childOptions = $this->decorator->buildOptions($autoChildOptions);
         $this->decorator->buildItem($child, $childOptions);
         if (isset($option['autochilds']) && $option['autochilds']) {
             $this->convertChildren($child, $options);
         }
     }
 }
开发者ID:CharguiTaieb,项目名称:MopaBootstrapBundle,代码行数:22,代码来源:MenuConverter.php

示例6: matchItem

 /**
  * {@inheritdoc}
  */
 public function matchItem(ItemInterface $item)
 {
     $children = $item->getChildren();
     $match = null;
     foreach ($children as $child) {
         if ($this->matcher->isCurrent($child)) {
             $match = true;
             break;
         }
     }
     return $match;
 }
开发者ID:drmjo,项目名称:SonataAdminBundle,代码行数:15,代码来源:ChildrenVoter.php

示例7: renderChildren

 /**
  * Renders all of the children of this menu.
  *
  * This calls ->renderItem() on each menu item, which instructs each
  * menu item to render themselves as an <li> tag (with nested ul if it
  * has children).
  * This method updates the depth for the children.
  *
  * @param \Knp\Menu\ItemInterface $item
  * @param array $options The options to render the item.
  * @return string
  */
 protected function renderChildren(ItemInterface $item, array $options)
 {
     // render children with a depth - 1
     if (null !== $options['depth']) {
         $options['depth'] = $options['depth'] - 1;
     }
     $html = '';
     foreach ($item->getChildren() as $child) {
         $html .= $this->renderItem($child, $options);
     }
     return $html;
 }
开发者ID:bamper,项目名称:symfony-ecommerce,代码行数:24,代码来源:CustomRenderer.php

示例8: isAncestor

 public function isAncestor(ItemInterface $item, $depth = null)
 {
     if (0 === $depth) {
         return false;
     }
     $childDepth = null === $depth ? null : $depth - 1;
     foreach ($item->getChildren() as $child) {
         if ($this->isCurrent($child) || $this->isAncestor($child, $childDepth)) {
             return true;
         }
     }
     return false;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:13,代码来源:Matcher.php

示例9: getCurrentItem

 /**
  * Get current item
  *
  * @param ItemInterface $item
  *
  * @return ItemInterface|null
  */
 private function getCurrentItem(ItemInterface $item)
 {
     foreach ($item->getChildren() as $child) {
         if ($this->matcher->isCurrent($child)) {
             return $child;
         } else {
             $child = $this->getCurrentItem($child);
             if ($child) {
                 return $child;
             }
         }
     }
     return null;
 }
开发者ID:paramonov,项目名称:MillwrightMenuBundle,代码行数:21,代码来源:BreadcrumbTwigRenderer.php

示例10: hasChildrenHelper

 /**
  * Specifies, whether the children of an item are displayed when rendering the menu
  *
  * @param ItemInterface $item
  *
  * @return bool
  */
 public function hasChildrenHelper(ItemInterface $item)
 {
     if (!$item->isDisplayed()) {
         return false;
     }
     foreach ($item->getChildren() as $child) {
         /** @var ItemInterface $child */
         if (!$child->getExtra("pageTree:hidden", false)) {
             // if we find a child which is not hidden, we need to render the menu
             return true;
         }
     }
     return false;
 }
开发者ID:cH40z-Lord,项目名称:BecklynPageTreeBundle,代码行数:21,代码来源:PageTreeTwigExtension.php

示例11: filterMenu

 public function filterMenu(ItemInterface $menu)
 {
     foreach ($menu->getChildren() as $child) {
         /** @var \Knp\Menu\MenuItem $child */
         $routes = $child->getExtra('routes');
         if ($routes !== null) {
             $route = current(current($routes));
             if ($route && !$this->hasRouteAccess($route)) {
                 $menu->removeChild($child);
             }
         }
         $this->filterMenu($child);
     }
     return $menu;
 }
开发者ID:timy-life,项目名称:symfony2-advanced-menus,代码行数:15,代码来源:Builder.php

示例12: reorderMenuItems

 /**
  * Reorder Menus items
  * 
  * @param ItemInterface $menu
  */
 protected function reorderMenuItems(ItemInterface $menu)
 {
     $menuOrderArray = array();
     $addLast = array();
     $alreadyTaken = array();
     foreach ($menu->getChildren() as $key => $menuItem) {
         if ($menuItem->hasChildren()) {
             $this->reorderMenuItems($menuItem);
         }
         $orderNumber = $menuItem->getExtra('orderNumber');
         if ($orderNumber != null) {
             if (!isset($menuOrderArray[$orderNumber])) {
                 $menuOrderArray[$orderNumber] = $menuItem->getName();
             } else {
                 $alreadyTaken[$orderNumber] = $menuItem->getName();
                 // $alreadyTaken[] = array('orderNumber' => $orderNumber, 'name' => $menuItem->getName());
             }
         } else {
             $addLast[] = $menuItem->getName();
         }
     }
     // sort them after first pass
     ksort($menuOrderArray);
     // handle position duplicates
     if (count($alreadyTaken)) {
         foreach ($alreadyTaken as $key => $value) {
             // the ever shifting target
             $keysArray = array_keys($menuOrderArray);
             $position = array_search($key, $keysArray);
             if ($position === false) {
                 continue;
             }
             $menuOrderArray = array_merge(array_slice($menuOrderArray, 0, $position), array($value), array_slice($menuOrderArray, $position));
         }
     }
     // sort them after second pass
     ksort($menuOrderArray);
     // add items without ordernumber to the end
     if (count($addLast)) {
         foreach ($addLast as $key => $value) {
             $menuOrderArray[] = $value;
         }
     }
     if (count($menuOrderArray)) {
         $menu->reorderChildren($menuOrderArray);
     }
 }
开发者ID:artscorestudio,项目名称:website-bundle,代码行数:52,代码来源:MenuBuilder.php

示例13: renderLabel

 protected function renderLabel(ItemInterface $item, array $options)
 {
     $html = '<i class="' . $item->getIcon() . '"></i> ';
     $html .= '<span>' . $item->getLabel() . '</span>';
     if ($item->hasChildren()) {
         $drop = false;
         foreach ($item->getChildren() as $child) {
             if (\App::isGranted($child->getPermissions())) {
                 $drop = true;
             }
         }
         if ($drop) {
             $html .= '<i class="fa fa-angle-left pull-right"></i>';
         }
     }
     return $html;
 }
开发者ID:santhapa,项目名称:ci-mag-cms,代码行数:17,代码来源:MenuRenderer.php

示例14: render

 public function render(ItemInterface $item, array $options = array())
 {
     $o = '<ul class="level1menu nav nav-sidebar">';
     foreach ($item->getChildren() as $item) {
         $o .= '<li';
         $current = false;
         if ($this->matcher->isCurrent($item)) {
             $current = true;
         }
         if ($this->matcher->isAncestor($item, 10)) {
             $current = true;
         }
         if ($current) {
             $o .= ' class="current"';
         }
         $o .= '>';
         $o .= '<a href="' . $this->urlGenerator->generate($item->getUri()) . '">';
         $o .= $item->getLabel();
         $o .= '</a>';
         if ($current) {
             foreach ($item->getChildren() as $subItem) {
                 $o .= '<ul>';
                 $current = false;
                 if ($this->matcher->isCurrent($subItem)) {
                     $current = true;
                 }
                 if ($this->matcher->isAncestor($subItem, 10)) {
                     $current = true;
                 }
                 $o .= '<li';
                 if ($current) {
                     $o .= ' class="current"';
                 }
                 $o .= '>';
                 $o .= '<a href="' . $this->urlGenerator->generate($subItem->getUri()) . '">';
                 $o .= $subItem->getLabel();
                 $o .= '</a>';
                 $o .= '</li>';
                 $o .= '</ul>';
             }
         }
         $o .= '</li>';
     }
     $o .= '</ul>';
     return $o;
 }
开发者ID:radvance,项目名称:radvance,代码行数:46,代码来源:Level1Renderer.php

示例15: renderChildren

 /**
  * Renders all of the children of this menu.
  *
  * This calls ->renderItem() on each menu item, which instructs each
  * menu item to render themselves as an <li> tag (with nested ul if it
  * has children).
  * This method updates the depth for the children.
  *
  * @param Item  $item
  * @param array $options The options to render the item.
  *
  * @return string
  */
 protected function renderChildren(Item $item, array $options)
 {
     // render children with a depth - 1
     if (null !== $options['depth']) {
         $options['depth'] = $options['depth'] - 1;
     }
     $html = '';
     foreach ($item->getChildren() as $child) {
         /* @var \CSBill\CoreBundle\Menu\MenuItem $child */
         if ($child->isDivider()) {
             $html .= $this->renderDivider($child, $options);
         } else {
             $html .= $this->renderItem($child, $options);
         }
     }
     return $html;
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:30,代码来源:Renderer.php


注:本文中的Knp\Menu\ItemInterface::getChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。