Commit 06de50da by Alexander Makarov

Merge pull request #4028 from umneeq/yii-widgets-menu-enh

Added ability to `yii\widgets\Menu` to encode each item's label separately
parents cc9c57e1 56e4f7ba
...@@ -114,6 +114,7 @@ Yii Framework 2 Change Log ...@@ -114,6 +114,7 @@ Yii Framework 2 Change Log
- Enh: Added support for array attributes in `in` validator (creocoder) - Enh: Added support for array attributes in `in` validator (creocoder)
- Enh: Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew and special characters (samdark) - Enh: Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew and special characters (samdark)
- Enh #3926: `yii\widgets\Breadcrumbs::$links`. Allows individual link to have its own `template` (creocoder, umneeq) - Enh #3926: `yii\widgets\Breadcrumbs::$links`. Allows individual link to have its own `template` (creocoder, umneeq)
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark) - Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark)
- Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark)
- Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)
......
...@@ -53,6 +53,8 @@ class Menu extends Widget ...@@ -53,6 +53,8 @@ class Menu extends Widget
* *
* - label: string, optional, specifies the menu item label. When [[encodeLabels]] is true, the label * - label: string, optional, specifies the menu item label. When [[encodeLabels]] is true, the label
* will be HTML-encoded. If the label is not specified, an empty string will be used. * will be HTML-encoded. If the label is not specified, an empty string will be used.
* - encode: boolean, optional, whether this item`s label should be HTML-encoded. This param will override
* global [[encodeLabels]] param.
* - url: string or array, optional, specifies the URL of the menu item. It will be processed by [[Url::to]]. * - url: string or array, optional, specifies the URL of the menu item. It will be processed by [[Url::to]].
* When this is set, the actual menu item content will be generated using [[linkTemplate]]; * When this is set, the actual menu item content will be generated using [[linkTemplate]];
* otherwise, [[labelTemplate]] will be used. * otherwise, [[labelTemplate]] will be used.
...@@ -255,7 +257,8 @@ class Menu extends Widget ...@@ -255,7 +257,8 @@ class Menu extends Widget
if (!isset($item['label'])) { if (!isset($item['label'])) {
$item['label'] = ''; $item['label'] = '';
} }
$items[$i]['label'] = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; $encodeLabel = $this->encodeLabels || isset($item['encode']) && $item['encode'] === true;
$items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$hasActiveChild = false; $hasActiveChild = false;
if (isset($item['items'])) { if (isset($item['items'])) {
$items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild); $items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild);
......
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