本文整理汇总了PHP中Knp\Menu\ItemInterface::getParent方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface::getParent方法的具体用法?PHP ItemInterface::getParent怎么用?PHP ItemInterface::getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Knp\Menu\ItemInterface
的用法示例。
在下文中一共展示了ItemInterface::getParent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render(ItemInterface $item, array $options = array())
{
$options = array_merge($this->defaultOptions, $options);
$translator = $options['translator'];
$itemIterator = new \Knp\Menu\Iterator\RecursiveItemIterator($item);
$iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
$items = [];
foreach ($iterator as $item) {
$translatedLabel = $translator->trans($item->getLabel());
$id = $item->getName();
$itemData = ['id' => strtolower($item->getName()), 'name' => $translatedLabel, 'uri' => $item->getUri()];
$itemData['has_children'] = $item->hasChildren();
$parentId = $item->getParent()->getName();
if ($parentId !== $id) {
$itemData['parent'] = strtolower($parentId);
if (!isset($items[$parentId]['children'])) {
$items[$parentId]['children'] = [];
}
$items[$parentId]['children'][] = $itemData;
}
if (isset($items[$id])) {
$items[$id] = array_merge($itemData, $items[$id]);
} else {
$items[$id] = $itemData;
}
}
return $items;
}
示例2: setActive
/**
* Set active class to current item and all its parents (so it is automatically opened)
*
* @param ItemInterface $item
*/
protected function setActive(ItemInterface $item = null)
{
if ($item) {
$this->setActive($item->getParent());
$item->setAttribute('class', $item->getAttribute('class', '') . ' active');
}
}
示例3: addSubMenu
protected function addSubMenu(ItemInterface $menu, $label)
{
$menu->addChild($label, array('uri' => '#'));
$menu[$label]->setAttribute('class', 'dropdown');
if ($menu->getParent()) {
$menu[$label]->setAttribute('class', 'dropdown-submenu');
$menu[$label]->setExtra('submenu', true);
}
$menu[$label]->setChildrenAttribute('class', 'dropdown-menu');
$menu[$label]->setChildrenAttribute('role', 'menu');
$menu[$label]->setLinkAttribute('class', 'dropdown-toggle');
$menu[$label]->setLinkAttribute('data-toggle', 'dropdown');
$menu[$label]->setLinkAttribute('role', 'button');
$menu[$label]->setLinkAttribute('aria-expanded', 'false');
}