Exemple #1
0
 /**
  * Get the evaluated contents of the object.
  *
  * @return string
  */
 public function render()
 {
     $output = '';
     foreach ($this->entries as $entry) {
         $entryAttributes = [];
         if ($entry instanceof DropdownDivider) {
             $entryAttributes['role'] = 'seperator';
             $entryAttributes['class'] = 'divider';
         } else {
             if ($entry instanceof DropdownHeader) {
                 $entryAttributes['class'] = 'dropdown-header';
             } else {
                 if (MenuHelper::isCurrentRoute($entry->getName())) {
                     $entryAttributes['class'] = 'active';
                 } else {
                     foreach ($entry->getAdditionalRouteNames() as $additionalRouteName) {
                         if (MenuHelper::isCurrentRoute($additionalRouteName)) {
                             $entryAttributes['class'] = ' active';
                         }
                     }
                 }
             }
         }
         $output .= '<li ' . Html::attributes($entryAttributes) . '>' . $entry->render() . '</li>';
     }
     if (empty($this->name)) {
         $link = Html::link('#', $this->title . '<span class="caret"></span>', ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown']);
     } else {
         $link = Html::linkRoute($this->name, $this->title . '<span class="caret"></span>', $this->parameters, ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown']);
     }
     return $link . '<ul class="dropdown-menu">' . $output . '</ul>';
 }
 /**
  * Get the evaluated contents of the object.
  *
  * @return string
  */
 public function render()
 {
     $output = '';
     foreach ($this->entries as $entry) {
         $entryAttributes = [];
         if ($entry instanceof Dropdown) {
             $entryAttributes['class'] = 'dropdown';
             foreach ($entry->getEntries() as $dropdownEntry) {
                 if ($dropdownEntry instanceof Link) {
                     foreach ($dropdownEntry->getAdditionalRouteNames() as $additionalRouteName) {
                         if (MenuHelper::isCurrentRoute($additionalRouteName)) {
                             $entryAttributes['class'] .= ' active';
                         }
                     }
                     if (MenuHelper::isCurrentRoute($dropdownEntry->getName())) {
                         $entryAttributes['class'] .= ' active';
                     }
                 }
             }
         } elseif ($entry instanceof Content) {
             $entryAttributes['class'] = 'navbar-text';
         } else {
             foreach ($entry->getAdditionalRouteNames() as $additionalRouteName) {
                 if (MenuHelper::isCurrentRoute($additionalRouteName)) {
                     $entryAttributes['class'] = ' active';
                 }
             }
             if (MenuHelper::isCurrentRoute($entry->getName())) {
                 $entryAttributes['class'] = 'active';
             }
         }
         if ($entry->isVisible()) {
             $output .= '<li ' . Html::attributes($entryAttributes) . '>' . $entry->render() . '</li>';
         }
     }
     return '<ul ' . Html::attributes($this->attributes) . '>' . $output . '</ul>';
 }
Exemple #3
0
 /**
  * Get the evaluated contents of the specified menu container.
  *
  * @param string|null $menuName
  * @return string
  * @throws MenuNotFoundException
  */
 public function render($menuName = null)
 {
     if (empty($menuName)) {
         $menuName = self::DEFAULT_MENU_NAME;
     }
     $menu = $this->menus->filter(function (MenuContainer $menu) use($menuName) {
         return $menu->getName() == $menuName;
     })->first();
     if ($menu instanceof MenuContainer) {
         return MenuHelper::purifyHtml(Html::decode($menu->render()));
     } else {
         throw new MenuNotFoundException($menuName);
     }
 }