Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ class Nav extends Widget
* - linkOptions: array, optional, the HTML attributes of the item's link.
* - options: array, optional, the HTML attributes of the item container (LI).
* - active: boolean, optional, whether the item should be on active state or not.
* - dropdown: boolean, optional, whether the item should be rendered as a [[Dropdown]].
* - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget,
* or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
*
* If a menu item is a string, it will be rendered directly without HTML encoding.
*/
public $items = [];
/**
* @var boolean whether the nav subitems should be a [[Dropdown]] widget.
*/
public $useDropdown = true;
/**
* @var boolean whether the nav items labels should be HTML-encoded.
*/
Expand Down Expand Up @@ -133,15 +138,20 @@ public function run()
*/
public function renderItems()
{
$items = [];
foreach ($this->items as $i => $item) {
return $this->renderItemsInternals($this->items, $this->options);
}

protected function renderItemsInternals($items, $options = [])
{
$rederedItems = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
}
$items[] = $this->renderItem($item);
$rederedItems[] = $this->renderItem($item);
}

return Html::tag('ul', implode("\n", $items), $this->options);
return Html::tag('ul', implode("\n", $rederedItems), $options);
}

/**
Expand All @@ -164,6 +174,7 @@ public function renderItem($item)
$items = ArrayHelper::getValue($item, 'items');
$url = ArrayHelper::getValue($item, 'url', '#');
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$dropdown = isset($item['dropdown']) ? $item['dropdown'] : $this->useDropdown;

if (isset($item['active'])) {
$active = ArrayHelper::remove($item, 'active', false);
Expand All @@ -172,17 +183,23 @@ public function renderItem($item)
}

if ($items !== null) {
$linkOptions['data-toggle'] = 'dropdown';
Html::addCssClass($options, 'dropdown');
Html::addCssClass($linkOptions, 'dropdown-toggle');
if ($this->dropDownCaret !== '') {
$label .= ' ' . $this->dropDownCaret;
if ($dropdown) {
$linkOptions['data-toggle'] = 'dropdown';
Html::addCssClass($options, 'dropdown');
Html::addCssClass($linkOptions, 'dropdown-toggle');
if ($this->dropDownCaret !== '') {
$label .= ' ' . $this->dropDownCaret;
}
}
if (is_array($items)) {
if ($this->activateItems) {
$items = $this->isChildActive($items, $active);
}
$items = $this->renderDropdown($items, $item);
if ($dropdown) {
$items = $this->renderDropdown($items, $item);
} else {
$items = $this->renderItemsInternals($items);
}
}
}

Expand Down