Exemplo n.º 1
0
 /**
  * @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;
 }
 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;
 }
Exemplo n.º 3
0
 public function getLevel()
 {
     return $this->parent ? $this->parent->getLevel() + 1 : 0;
 }
Exemplo n.º 4
0
    /**
     * 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());
    }
Exemplo n.º 5
0
 protected function getRealLevel(ItemInterface $item, array $options)
 {
     return $item->getLevel() - $options['rootLevel'];
 }
Exemplo n.º 6
0
 /**
  * @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);
 }
 /**
  * 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);
 }