本文整理匯總了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');
}