From 8a1bf04599e7351cd7eb5be5edb7997d8f134fc9 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 26 Aug 2013 01:23:27 +0400 Subject: [PATCH] Fixes #790: added visible for Nav and Dropdown --- framework/yii/bootstrap/Dropdown.php | 7 ++++++- framework/yii/bootstrap/Nav.php | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/yii/bootstrap/Dropdown.php b/framework/yii/bootstrap/Dropdown.php index fdc0095..1cc389e 100644 --- a/framework/yii/bootstrap/Dropdown.php +++ b/framework/yii/bootstrap/Dropdown.php @@ -26,6 +26,7 @@ class Dropdown extends Widget * * - label: string, required, the label of the item link * - url: string, optional, the url of the item link. Defaults to "#". + * - visible: boolean, optional, whether this menu item is visible. Defaults to true. * - linkOptions: array, optional, the HTML attributes of the item link. * - options: array, optional, the HTML attributes of the item. */ @@ -64,7 +65,11 @@ class Dropdown extends Widget protected function renderItems($items) { $lines = array(); - foreach ($items as $item) { + foreach ($items as $i => $item) { + if (isset($item['visible']) && !$item['visible']) { + unset($items[$i]); + continue; + } if (is_string($item)) { $lines[] = $item; continue; diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index 186c20a..ee103d4 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -60,6 +60,7 @@ class Nav extends Widget * * - label: string, required, the nav item label. * - url: optional, the item's URL. Defaults to "#". + * - visible: boolean, optional, whether this menu item is visible. Defaults to true. * - 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. @@ -123,7 +124,11 @@ class Nav extends Widget public function renderItems() { $items = array(); - foreach ($this->items as $item) { + foreach ($this->items as $i => $item) { + if (isset($item['visible']) && !$item['visible']) { + unset($items[$i]); + continue; + } $items[] = $this->renderItem($item); }