本文整理汇总了PHP中MenuItem::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP MenuItem::addChild方法的具体用法?PHP MenuItem::addChild怎么用?PHP MenuItem::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItem
的用法示例。
在下文中一共展示了MenuItem::addChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addItem
/**
* Adiciona um item ao menu.
* @param string $name Texto que será exibido ao usuário
* @param string $link Link do item do menu
* @return MenuItem O item do menu recém adicionado
*/
public function addItem($name, $link)
{
$menuItem = new MenuItem();
$anchor = $menuItem->addChild(new Anchor($link));
$anchor->addChild(new Text($name));
$this->addChild($menuItem);
return $menuItem;
}
示例2: createFromNode
/**
* Create a menu item from a NodeInterface
*
* @param NodeInterface $node
* @return MenuItem
*/
public function createFromNode(NodeInterface $node)
{
$item = new MenuItem($node->getName(), $this->getUriFromNode($node), $node->getAttributes());
$item->setLabel($node->getLabel());
foreach ($node->getChildren() as $childNode) {
$item->addChild($this->createFromNode($childNode));
}
return $item;
}
示例3: buildTree
/**
* Recursively creates a tree from the pages array
*
* @param MenuItem parent MenuItem object under which the tree is build
* @param array pageIdx indices of pages for this tree
*/
private function buildTree(MenuItem &$parent, $pageIdx)
{
foreach ($pageIdx as $i) {
if ($this->pages[$i]->parent == $parent->get('id')) {
$child = $parent->addChild($this->pages[$i]);
$this->buildTree($child, array_diff($pageIdx, array($i)));
if ($this->pid == $this->pages[$i]->id) {
$parent->getRoot()->setCurrentItem($child);
}
}
}
}
示例4: setupMenuItem
/**
* @param MenuItem $menu
* @param Array $menudata
* @param String $menuItemDecorator
* */
public function setupMenuItem($menu, $menudata, $menuItemDecorator)
{
$menuItemCounter = 0;
foreach ($menudata as $menuItem) {
$menuType = $menuItem->getMenuType();
$getPageFunction = 'get' . $menuType;
$menuItemCounter++;
if ($menuItem->getPublishstate() != '0') {
$urlParams = $menuItem->getMenuUrlExtras();
if (!empty($urlParams)) {
$urlParams = '/' . urlencode($urlParams);
}
switch ($menuType) {
case 'http':
$targetURL = $menuItem->getExternalUrl();
if ($targetURL === null) {
$targetURL = '#';
}
$menu->addChild($menuItem->getTitle(), array('uri' => $targetURL));
$menu[$menuItem->getTitle()]->setLinkAttribute('target', '_blank');
$menu[$menuItem->getTitle()]->setLinkAttribute('rel', 'nofollow');
break;
case 'url':
$targetURL = $menuItem->getExternalUrl();
if ($targetURL === null) {
$targetURL = '#';
}
$menu->addChild($menuItem->getTitle(), array('uri' => $targetURL));
break;
case 'seperator':
$menu->addChild($menuItem->getTitle());
$menu[$menuItem->getTitle()]->setLabelAttribute('class', 'divider');
break;
case 'Page':
$pageFunction = $menuItem->{$getPageFunction}();
// If Link Action is not selected point to homepage else to alias or page id based route
if ($pageFunction !== null) {
$alias = $this->getPageAlias($pageFunction, $menuType);
if (null === $alias) {
$menu->addChild($menuItem->getTitle(), array('uri' => '/' . $menuItem->getRoute() . '/' . $pageFunction . $urlParams));
} elseif ('index' === $alias) {
$menu->addChild($menuItem->getTitle(), array('uri' => '/'));
} else {
$menu->addChild($menuItem->getTitle(), array('uri' => '/' . $alias . $urlParams));
}
} else {
$menu->addChild($menuItem->getTitle(), array('uri' => '/'));
}
break;
case 'Blog':
$pageFunction = $menuItem->{$getPageFunction}();
// If Link Action is not selected point to homepage else to alias or page id based route
if ($pageFunction !== null) {
$alias = $this->getPageAlias($pageFunction, $menuType);
if (null === $alias) {
$menu->addChild($menuItem->getTitle(), array('uri' => '/' . strtolower($menuType) . '/' . $menuItem->getRoute() . '/' . $menuItem->{$getPageFunction}() . $urlParams));
} else {
$menu->addChild($menuItem->getTitle(), array('uri' => '/' . strtolower($menuType) . '/' . $alias . $urlParams));
}
} else {
$menu->addChild($menuItem->getTitle(), array('uri' => '/'));
}
break;
default:
$menu->addChild($menuItem->getTitle());
$menu[$menuItem->getTitle()]->setLabelAttribute('class', 'divider');
}
$menu[$menuItem->getTitle()]->setAttribute('class', 'item' . $menuItemCounter . ' level' . $this->menuItemlevel);
$menu[$menuItem->getTitle()]->setLinkAttribute('class', 'item' . $menuItemCounter . ' level' . $this->menuItemlevel);
$menu[$menuItem->getTitle()]->setLinkAttribute('title', $menuItem->getTitle());
if ($menuItemDecorator == 'main') {
if ($menuItem->getMenuImage() !== null) {
$menu[$menuItem->getTitle()]->setLabelAttribute('style', 'background-image:url("' . $menuItem->getMenuImage() . '");');
}
if ($menuItem->children !== null) {
$menu[$menuItem->getTitle()]->setAttribute('class', 'item' . $menuItemCounter . ' level' . $this->menuItemlevel . ' has-dropdown not-click');
$this->menuItemlevel = $this->menuItemlevel + 1;
//$menu[$menuItem->getTitle()]->setAttribute('flyout-toggle', true);
$menu[$menuItem->getTitle()]->setChildrenAttribute('class', 'dropdown level' . $this->menuItemlevel);
$this->setupMenuItem($menu[$menuItem->getTitle()], $menuItem->children, $menuItemDecorator);
$this->menuItemlevel = $this->menuItemlevel - 1;
}
} else {
if ($menuItem->children !== null) {
$this->menuItemlevel = $this->menuItemlevel + 1;
$menu[$menuItem->getTitle()]->setAttribute('class', 'item' . $menuItemCounter . ' level' . $this->menuItemlevel);
$this->setupMenuItem($menu[$menuItem->getTitle()], $menuItem->children, $menuItemDecorator);
$this->menuItemlevel = $this->menuItemlevel - 1;
}
}
}
}
}