Skip to content

Commit f41768b

Browse files
PowerGamer1samdark
authored andcommitted
Update Dropdown.php (#149)
Two changes: 1. Documented previously undocumented 'encode' item option. 2. Moved `is_string($item)` check to occur BEFORE `$item` is handled as array. When `$item` is a string `$item['visible']` would not be an error and will return the first character of that string. Doing `!$item['visible']` on the first character of a string does not make any sense.
1 parent 1248483 commit f41768b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Dropdown.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Dropdown extends Widget
3838
* @var array list of menu items in the dropdown. Each array element can be either an HTML string,
3939
* or an array representing a single menu with the following structure:
4040
*
41-
* - label: string, required, the label of the item link
41+
* - label: string, required, the label of the item link.
42+
* - encode: boolean, optional, whether to HTML-ecnode item label.
4243
* - url: string|array, optional, the url of the item link. This will be processed by [[Url::to()]].
4344
* If not set, the item will be treated as a menu header when the item has no sub-menu.
4445
* - visible: boolean, optional, whether this menu item is visible. Defaults to true.
@@ -101,13 +102,13 @@ protected function renderItems($items, $options = [])
101102
{
102103
$lines = [];
103104
foreach ($items as $item) {
104-
if (isset($item['visible']) && !$item['visible']) {
105-
continue;
106-
}
107105
if (is_string($item)) {
108106
$lines[] = $item;
109107
continue;
110108
}
109+
if (isset($item['visible']) && !$item['visible']) {
110+
continue;
111+
}
111112
if (!array_key_exists('label', $item)) {
112113
throw new InvalidConfigException("The 'label' option is required.");
113114
}

0 commit comments

Comments
 (0)