本文整理汇总了PHP中Knp\Menu\ItemInterface::getLevel方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface::getLevel方法的具体用法?PHP ItemInterface::getLevel怎么用?PHP ItemInterface::getLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Knp\Menu\ItemInterface
的用法示例。
在下文中一共展示了ItemInterface::getLevel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderItem
/**
* @param ItemInterface $item
* @param array $options
*
* @return string
*/
protected function renderItem(ItemInterface $item, array $options)
{
// if we don't have access or this item is marked to not be shown
if (!$item->isDisplayed()) {
return '';
}
// create an array than can be imploded as a class list
$class = (array) $item->getAttribute('class');
if ($item->getLevel() === 1) {
$class[] = 'treeview';
}
if ($this->matcher->isCurrent($item) || $this->matcher->isAncestor($item, $options['matchingDepth'])) {
$class[] = $options['currentClass'];
}
// retrieve the attributes and put the final class string back on it
$attributes = $item->getAttributes();
if (!empty($class)) {
$attributes['class'] = implode(' ', $class);
}
// opening li tag
$html = $this->format('<li' . $this->renderHtmlAttributes($attributes) . '>', 'li', $item->getLevel(), $options);
// render the text/link inside the li tag
//$html .= $this->format($item->getUri() ? $item->renderLink() : $item->renderLabel(), 'link', $item->getLevel());
$html .= $this->renderLink($item, $options);
// renders the embedded ul
$childrenClass = (array) $item->getChildrenAttribute('class');
$childrenClass[] = 'treeview-menu';
$childrenAttributes = $item->getChildrenAttributes();
$childrenAttributes['class'] = implode(' ', $childrenClass);
$html .= $this->renderList($item, $childrenAttributes, $options);
// closing li tag
$html .= $this->format('</li>', 'li', $item->getLevel(), $options);
return $html;
}
示例2: renderList
protected function renderList(ItemInterface $item, array $attributes, array $options)
{
/*
* Return an empty string if any of the following are true:
* a) The menu has no children eligible to be displayed
* b) The depth is 0
* c) This menu item has been explicitly set to hide its children
*/
if (!$item->hasChildren() || 0 === $options['depth'] || !$item->getDisplayChildren()) {
return '';
}
$html = $this->format('<div' . $this->renderHtmlAttributes($attributes) . '>', 'ul', $item->getLevel(), $options);
$html .= $this->renderChildren($item, $options);
$html .= $this->format('</div>', 'ul', $item->getLevel(), $options);
return $html;
}
示例3: getLevel
public function getLevel()
{
return $this->parent ? $this->parent->getLevel() + 1 : 0;
}
示例4: renderLink
/**
* Renders the link in a a tag with link attributes or
* the label in a span tag with label attributes
*
* Tests if item has a an uri and if not tests if it's
* the current item and if the text has to be rendered
* as a link or not.
*
* @param \Knp\Menu\ItemInterface $item The item to render the link or label for
* @param array $options The options to render the item
* @return string
*/
public function renderLink(ItemInterface $item, array $options = array())
{
$options = array_merge($this->getDefaultOptions(), $options);
if ($item->getUri() && (!$item->isCurrent() || $options['currentAsLink'])) {
$text = sprintf('<a href="%s"%s>%s</a>', $this->escape($item->getUri()), $this->renderHtmlAttributes($item->getLinkAttributes()), $this->escape($item->getLabel()));
} else {
$text = sprintf('<span%s>%s</span>', $this->renderHtmlAttributes($item->getLabelAttributes()), $this->escape($item->getLabel()));
}
return $this->format($text, 'link', $item->getLevel());
}
示例5: getRealLevel
protected function getRealLevel(ItemInterface $item, array $options)
{
return $item->getLevel() - $options['rootLevel'];
}
示例6: renderDivider
/**
* @param Item $item
* @param array $options
*
* @return string
*/
protected function renderDivider(Item $item, array $options = array())
{
return $this->format('<li' . $this->renderHtmlAttributes(array('class' => 'divider' . $item->getExtra('divider'))) . '>', 'li', $item->getLevel(), $options);
}
示例7: getChildOptions
/**
* Gets guessed values for different menu/nav types.
*
* @param ItemInterface $item
* @param array $options
*
* @return array
*/
protected function getChildOptions(ItemInterface $item, array $options)
{
$childOptions = array();
$hasChildren = $item->hasChildren() && (!isset($options['depth']) || $options['depth'] > $item->getLevel());
if (in_array($options['automenu'], array('navbar')) && $hasChildren) {
$childOptions = array('dropdown' => !isset($options['dropdown']) || $options['dropdown'], 'caret' => !isset($options['caret']) || $options['caret']);
}
if (in_array($options['automenu'], array('list-group'))) {
$childOptions = array('list-group-item' => true);
}
return array_merge($options, $childOptions);
}