Skip to content

Commit

Permalink
Nav widget fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jirisvoboda committed Dec 1, 2015
1 parent 3e103be commit 43c615b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions widgets/Nav.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class Nav extends \yii\bootstrap\Nav {
*/
const ITEM_DIVIDER = 'divider';

/**
* Tags
*/
const TAG_LINK = 'a';

/**
* @var array list of items in the nav widget. Each array element represents a single
* menu item which can be either a string or an array with the following structure:
Expand Down Expand Up @@ -135,7 +140,7 @@ public function renderItem($item)
}

$items = ArrayHelper::getValue($item, 'items');

if ($items === null)
{
return parent::renderItem($item);
Expand All @@ -145,7 +150,7 @@ public function renderItem($item)
{
throw new InvalidConfigException("The 'label' option is required.");
}

$dropdownType = ArrayHelper::getValue($item, 'dropdownType', self::TYPE_DEFAULT);
$options = ArrayHelper::getValue($item, 'options', []);

Expand Down Expand Up @@ -218,14 +223,26 @@ private function _getLinkTag($item)

Html::addCssClass($linkOptions, 'dropdown-toggle');

$tag = ArrayHelper::getValue($item, 'tag', 'a');

$url = ArrayHelper::getValue($item, 'url', false);

if (!$url)
{
return Html::a($label, 'javascript:;', $linkOptions);
if (self::TAG_LINK == $tag)
{
$linkOptions['href'] = 'javascript:;';
}

return Html::tag($tag, $label, $linkOptions);
}

if (self::TAG_LINK == $tag)
{
$linkOptions['href'] = Url::toRoute(ArrayHelper::getValue($item, 'url', '#'));
}

return Html::a($label, Url::toRoute(ArrayHelper::getValue($item, 'url', '#')), $linkOptions);
return Html::tag($tag, $label, $linkOptions);
}

/**
Expand Down

0 comments on commit 43c615b

Please sign in to comment.