Commit f41768b3 authored by PowerGamer1's avatar PowerGamer1 Committed by Alexander Makarov

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.
parent 12484837
......@@ -38,7 +38,8 @@ class Dropdown extends Widget
* @var array list of menu items in the dropdown. Each array element can be either an HTML string,
* or an array representing a single menu with the following structure:
*
* - label: string, required, the label of the item link
* - label: string, required, the label of the item link.
* - encode: boolean, optional, whether to HTML-ecnode item label.
* - url: string|array, optional, the url of the item link. This will be processed by [[Url::to()]].
* If not set, the item will be treated as a menu header when the item has no sub-menu.
* - visible: boolean, optional, whether this menu item is visible. Defaults to true.
......@@ -101,13 +102,13 @@ class Dropdown extends Widget
{
$lines = [];
foreach ($items as $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (isset($item['visible']) && !$item['visible']) {
continue;
}
if (!array_key_exists('label', $item)) {
throw new InvalidConfigException("The 'label' option is required.");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment