Skip to content
Closed
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
22 changes: 16 additions & 6 deletions extensions/bootstrap/Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class Nav extends Widget
* 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 $asDropdown = true;
/**
* @var boolean whether the nav items labels should be HTML-encoded.
*/
Expand Down Expand Up @@ -114,25 +118,25 @@ public function init()
*/
public function run()
{
echo $this->renderItems();
echo $this->renderItems($this->items, $this->options);
BootstrapAsset::register($this->getView());
}

/**
* Renders widget items.
*/
public function renderItems()
public function renderItems($items, $options = [])
{
$items = [];
foreach ($this->items as $i => $item) {
$rederedItems = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
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 Down Expand Up @@ -163,20 +167,26 @@ public function renderItem($item)
}

if ($items !== null) {
if ($this->asDropdown) {
$linkOptions['data-toggle'] = 'dropdown';
Html::addCssClass($options, 'dropdown');
Html::addCssClass($linkOptions, 'dropdown-toggle');
$label .= ' ' . Html::tag('b', '', ['class' => 'caret']);
}
if (is_array($items)) {
if ($this->activateItems) {
$items = $this->isChildActive($items, $active);
}
if ($this->asDropdown) {
$items = Dropdown::widget([
'items' => $items,
'encodeLabels' => $this->encodeLabels,
'clientOptions' => false,
'view' => $this->getView(),
]);
} else {
$items = $this->renderItems($items);
}
}
}

Expand Down