本文整理汇总了PHP中Knp\Menu\ItemInterface::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface::getName方法的具体用法?PHP ItemInterface::getName怎么用?PHP ItemInterface::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Knp\Menu\ItemInterface
的用法示例。
在下文中一共展示了ItemInterface::getName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: render
public function render(ItemInterface $item, array $options = array())
{
$options = array_merge(array('currentClass' => 'active'), $options);
if ('root' === $item->getName()) {
$item->setChildrenAttribute('class', trim('nav navbar-nav ' . $item->getAttribute('class')));
}
return parent::render($item, $options);
}
示例3: addCurrent
public function addCurrent(ItemInterface $menu)
{
$currentRoute = $this->stack->getMasterRequest()->get('_route');
$route = $this->menu[$menu->getName()]['route'];
if ($currentRoute == $route) {
$menu->setCurrent(true);
}
}
示例4: renderSpanElement
protected function renderSpanElement(ItemInterface $item, array $options)
{
return sprintf('<span%s>%s</span>', $this->renderHtmlAttributes($item->getLabelAttributes()), $item->getName());
}
示例5: setContext
/**
* Set uri, display context to menu item
*
* @param MenuItemInterface $item
* @param array $routeParameters
* @param array $options
*
* @return MenuFactoryInterface
*/
protected function setContext(MenuItemInterface $item, array $routeParameters = array(), array $options = array())
{
$display = true;
$rootItem = !$item->getName();
$token = $this->security->getToken();
if ($token) {
if ($options['roles'] && !$this->security->isGranted($options['roles'])) {
$display = false;
}
if ($display) {
foreach ((array) $item->getExtra('oids') as $oidItem) {
if (!$this->security->isGranted($oidItem['permissions'], $oidItem['oid'])) {
$display = false;
break;
}
}
}
}
if ($options['route'] && !$rootItem) {
$acceptedRouteParameters = array_intersect_key($routeParameters, $options['routeAcceptedParameters']);
if ($options['routeRequiredParameters'] === $options['routeAcceptedParameters']) {
$uri = $this->router->generate($options['route'], $acceptedRouteParameters, $options['routeAbsolute']);
$item->setUri($uri);
} else {
$display = false;
}
}
if (!$display) {
if ($options['showNonAuthorized'] && !$token) {
$display = true;
}
if ($options['showAsText']) {
$display = true;
$item->setUri(null);
}
}
if (!$display) {
$item->setDisplay(false);
}
return $this;
}
示例6: moveChildToPosition
/**
* Moves child to specified position. Rearange other children accordingly.
*
* @param \Knp\Menu\ItemInterface $child Child to move.
* @param integer $position Position to move child to.
* @return \Knp\Menu\ItemInterface
*/
public function moveChildToPosition(ItemInterface $child, $position)
{
$name = $child->getName();
$order = array_keys($this->children);
$oldPosition = array_search($name, $order);
unset($order[$oldPosition]);
$order = array_values($order);
array_splice($order, $position, 0, $name);
$this->reorderChildren($order);
return $this;
}
示例7: toArray
/**
* @param ItemInterface $item
* @param integer|null $depth the depth until which children should be exported (null means unlimited)
*
* @return array
*/
public function toArray(ItemInterface $item, $depth = null)
{
$array = array('name' => $item->getName(), 'label' => $item->getLabel(), 'uri' => $item->getUri(), 'attributes' => $item->getAttributes(), 'labelAttributes' => $item->getLabelAttributes(), 'linkAttributes' => $item->getLinkAttributes(), 'childrenAttributes' => $item->getChildrenAttributes(), 'extras' => $item->getExtras(), 'display' => $item->isDisplayed(), 'displayChildren' => $item->getDisplayChildren(), 'current' => $item->isCurrent());
// export the children as well, unless explicitly disabled
if (0 !== $depth) {
$childDepth = null === $depth ? null : $depth - 1;
$array['children'] = array();
foreach ($item->getChildren() as $key => $child) {
$array['children'][$key] = $this->toArray($child, $childDepth);
}
}
return $array;
}