mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 06:17:56 +08:00
Fixes #790: added visible for Nav and Dropdown
This commit is contained in:
@@ -26,6 +26,7 @@ class Dropdown extends Widget
|
|||||||
*
|
*
|
||||||
* - label: string, required, the label of the item link
|
* - label: string, required, the label of the item link
|
||||||
* - url: string, optional, the url of the item link. Defaults to "#".
|
* - 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.
|
* - linkOptions: array, optional, the HTML attributes of the item link.
|
||||||
* - options: array, optional, the HTML attributes of the item.
|
* - options: array, optional, the HTML attributes of the item.
|
||||||
*/
|
*/
|
||||||
@@ -64,7 +65,11 @@ class Dropdown extends Widget
|
|||||||
protected function renderItems($items)
|
protected function renderItems($items)
|
||||||
{
|
{
|
||||||
$lines = array();
|
$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)) {
|
if (is_string($item)) {
|
||||||
$lines[] = $item;
|
$lines[] = $item;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class Nav extends Widget
|
|||||||
*
|
*
|
||||||
* - label: string, required, the nav item label.
|
* - label: string, required, the nav item label.
|
||||||
* - url: optional, the item's URL. Defaults to "#".
|
* - 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.
|
* - linkOptions: array, optional, the HTML attributes of the item's link.
|
||||||
* - options: array, optional, the HTML attributes of the item container (LI).
|
* - options: array, optional, the HTML attributes of the item container (LI).
|
||||||
* - active: boolean, optional, whether the item should be on active state or not.
|
* - active: boolean, optional, whether the item should be on active state or not.
|
||||||
@@ -123,7 +124,11 @@ class Nav extends Widget
|
|||||||
public function renderItems()
|
public function renderItems()
|
||||||
{
|
{
|
||||||
$items = array();
|
$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);
|
$items[] = $this->renderItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user