Browse Source

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.
tags/2.0.7
PowerGamer1 8 years ago committed by Alexander Makarov
parent
commit
f41768b3ad
  1. 9
      Dropdown.php

9
Dropdown.php

@ -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.");
}

Loading…
Cancel
Save