本文整理汇总了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));
}
}
}
示例2: removeFactory
/**
* Рекурсивный метод для удаления фабрики, что позволяет кешировать объект меню.
*
* @param ItemInterface $menu
*/
protected function removeFactory(ItemInterface $menu)
{
$menu->setFactory(new DummyFactory());
foreach ($menu->getChildren() as $subMenu) {
$this->removeFactory($subMenu);
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}