예제 #1
0
    /**
     * Called by the parent menu item to render this menu.
     *
     * This renders the li tag to fit into the parent ul as well as its
     * own nested ul tag if this menu item has children
     *
     * @param \Knp\Menu\ItemInterface $item
     * @param array $options The options to render the item
     * @return string
     */
    public function renderItem(ItemInterface $item, array $options = array())
    {
        $options = array_merge($this->getDefaultOptions(), $options);

        // if we don't have access or this item is marked to not be shown
        if (!$item->isDisplayed()) {
            return '';
        }

        // explode the class string into an array of classes
        $class = ($item->getAttribute('class')) ? explode(' ', $item->getAttribute('class')) : array();

        if ($item->isCurrent()) {
            $class[] = $options['currentClass'];
        } elseif ($item->isCurrentAncestor()) {
            $class[] = $options['ancestorClass'];
        }

        if ($item->actsLikeFirst()) {
            $class[] = $options['firstClass'];
        }
        if ($item->actsLikeLast()) {
            $class[] = $options['lastClass'];
        }

        // 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());

        // 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 if there are visible children
        if ($item->hasChildren() && 0 !== $options['depth'] && $item->getDisplayChildren()) {

            $childrenClass = ($item->getChildrenAttribute('class')) ? explode(' ', $item->getChildrenAttribute('class')) : array();
            $childrenClass[] = 'menu_level_'.$item->getLevel();

            $childrenAttributes = $item->getChildrenAttributes();
            $childrenAttributes['class'] = implode(' ', $childrenClass);

            $html .= $this->format('<ul'.$this->renderHtmlAttributes($childrenAttributes).'>', 'ul', $item->getLevel());
            $html .= $this->renderChildren($item, $options);
            $html .= $this->format('</ul>', 'ul', $item->getLevel());
        }

        // closing li tag
        $html .= $this->format('</li>', 'li', $item->getLevel());

        return $html;
    }
 /**
  * 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
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;
 }
예제 #4
0
 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);
 }
예제 #5
0
 /**
  * Called by the parent menu item to render this menu.
  *
  * This renders the li tag to fit into the parent ul as well as its
  * own nested ul tag if this menu item has children
  *
  * @param ItemInterface $item
  * @param array         $options The options to render the item
  *
  * @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 ($this->matcher->isCurrent($item)) {
         $class[] = $options['currentClass'];
     } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) {
         $class[] = $options['ancestorClass'];
     }
     if ($item->actsLikeFirst()) {
         $class[] = $options['firstClass'];
     }
     if ($item->actsLikeLast()) {
         $class[] = $options['lastClass'];
     }
     if ($item->hasChildren() && $options['depth'] !== 0) {
         if (null !== $options['branch_class'] && $item->getDisplayChildren()) {
             $class[] = $options['branch_class'];
         }
     } elseif (null !== $options['leaf_class']) {
         $class[] = $options['leaf_class'];
     }
     // retrieve the attributes and put the final class string back on it
     $attributes = $item->getAttributes();
     if (!empty($class)) {
         $attributes['class'] = implode(' ', $class);
     }
     $html = '';
     $isRightMenu = $item->getExtra('type', 'left-menu') === 'right-menu';
     // Don't render the container if the menu has children but is a right aligned menu
     if ($item->hasChildren() && !$isRightMenu) {
         // opening li tag
         $html = $this->format('<div' . $this->renderHtmlAttributes($attributes) . '>', 'li', $item->getLevel(), $options);
     }
     // render the text/link inside the li tag
     if (!$isRightMenu) {
         $html .= $this->renderLink($item, $options);
     }
     if ($item->hasChildren()) {
         // renders the embedded ul
         $childrenClass = (array) $item->getChildrenAttribute('class');
         $childrenClass[] = 'menu_level_' . $item->getLevel();
         $childrenAttributes = $item->getChildrenAttributes();
         $childrenAttributes['class'] = implode(' ', $childrenClass);
         $html .= $this->renderList($item, $childrenAttributes, $options);
         // closing li tag
         $html .= $this->format('</div>', 'li', $item->getLevel(), $options);
     }
     return $html;
 }
예제 #6
0
 protected function renderItem(ItemInterface $item, array $options)
 {
     if (!\App::isGranted($item->getPermissions())) {
         return '';
     }
     // 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 ($this->matcher->isCurrent($item)) {
         $class[] = $options['currentClass'];
     } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) {
         $class[] = $options['ancestorClass'];
     }
     if ($item->actsLikeFirst()) {
         $class[] = $options['firstClass'];
     }
     if ($item->actsLikeLast()) {
         $class[] = $options['lastClass'];
     }
     if ($item->hasChildren() && $options['depth'] !== 0) {
         if (null !== $options['branch_class'] && $item->getDisplayChildren()) {
             $class[] = $options['branch_class'];
         }
     } elseif (null !== $options['leaf_class']) {
         $class[] = $options['leaf_class'];
     }
     // 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[] = 'menu_level_'.$item->getLevel();
     $childrenAttributes = $item->getChildrenAttributes();
     // has been set implocitly here, can use ->setChildrenAttributes(array('class'=> 'treeview-menu')) while menu creating
     $childrenAttributes['class'] = 'treeview-menu';
     $childrenAttributes['class'] .= implode(' ', $childrenClass);
     $html .= $this->renderList($item, $childrenAttributes, $options);
     // closing li tag
     $html .= $this->format('</li>', 'li', $item->getLevel(), $options);
     return $html;
 }
 /**
  * Builds a menu item based.
  *
  * @param ItemInterface $item
  * @param array         $options
  */
 public function buildItem(ItemInterface $item, array $options)
 {
     if ($options['navbar']) {
         $item->setChildrenAttribute('class', 'nav navbar-nav');
     }
     if ($options['pills']) {
         $item->setChildrenAttribute('class', 'nav nav-pills');
     }
     if ($options['stacked']) {
         $class = $item->getChildrenAttribute('class');
         $item->setChildrenAttribute('class', $class . ' nav-stacked');
     }
     if ($options['dropdown-header']) {
         $item->setAttribute('role', 'presentation')->setAttribute('class', 'dropdown-header')->setUri(null);
     }
     if ($options['list-group']) {
         $item->setChildrenAttribute('class', 'list-group');
         $item->setAttribute('class', 'list-group-item');
     }
     if ($options['list-group-item']) {
         $item->setAttribute('class', 'list-group-item');
     }
     if ($options['dropdown']) {
         $item->setUri('#')->setAttribute('class', trim('dropdown ' . $item->getAttribute('class')))->setLinkAttribute('class', 'dropdown-toggle')->setLinkAttribute('data-toggle', 'dropdown')->setChildrenAttribute('class', 'dropdown-menu')->setChildrenAttribute('role', 'menu');
         if ($options['caret']) {
             $item->setExtra('caret', 'true');
         }
     }
     if ($options['divider']) {
         $item->setLabel('')->setUri(null)->setAttribute('role', 'presentation')->setAttribute('class', 'divider');
     }
     if ($options['pull-right']) {
         $className = $options['navbar'] ? 'navbar-right' : 'pull-right';
         $class = $item->getChildrenAttribute('class', '');
         $item->setChildrenAttribute('class', $class . ' ' . $className);
     }
     if ($options['icon']) {
         $item->setExtra('icon', $options['icon']);
     }
 }
예제 #8
0
 /**
  * @param \Knp\Menu\ItemInterface $item
  * @param array $options
  * @return \Nette\Utils\Html|null
  */
 protected function getItem(ItemInterface $item, array $options)
 {
     if (!$item->isDisplayed()) {
         return null;
     }
     // create an array than can be imploded as a class list
     $class = (array) $item->getAttribute('class');
     if ($this->matcher->isCurrent($item)) {
         $class[] = $options['currentClass'];
     } elseif ($this->matcher->isAncestor($item, $options['ancestorCurrencyDepth'])) {
         $class[] = $options['ancestorClass'];
     }
     if ($item->actsLikeFirst()) {
         $class[] = $options['firstClass'];
     }
     if ($item->actsLikeLast()) {
         $class[] = $options['lastClass'];
     }
     // retrieve the attributes and put the final class string back on it
     $attributes = $item->getAttributes();
     if (!empty($class)) {
         $attributes['class'] = $class;
     }
     $li = Html::el('li', $attributes);
     if (($link = $this->getLink($item, $options)) !== null) {
         $li->add($link);
     }
     // renders the embedded ul
     $childrenClass = (array) $item->getChildrenAttribute('class');
     $childrenClass[] = 'menu_level_' . $item->getLevel();
     $childrenAttributes = $item->getChildrenAttributes();
     $childrenAttributes['class'] = $childrenClass;
     if (($children = $this->getList($item, $childrenAttributes, $options)) !== null) {
         $li->add($children);
     }
     return $li;
 }