/** * 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>'; }
/** * This adds the necessary classes to chunk HTML for them to be picked up by the JS editor. * i.e. it makes chunks editable. * * @param string $html HTML to add classes to. * * @return string */ public function addAttributesToHtml($html) { $html = trim((string) $html); $attributes = array_merge($this->getRequiredAttributes(), $this->attributes()); $attributesString = Html::attributes($attributes); return preg_replace('|<(.*?)>|', "<\$1{$attributesString}>", $html, 1); }
/** * Get html attribute data * * @access public * @return string|null */ public function getAttributes() { return $this->has('attributes') ? HTML::attributes($this->get('attributes')) : null; }
/** * Get HTML attribute data. * * @return mixed */ public function getAttributes() { $attributes = $this->attributes; array_forget($attributes, ['active', 'icon']); return HTML::attributes($attributes); }