From 81bcd116a83dc24c9db2d8cd73f65074e09863bf Mon Sep 17 00:00:00 2001 From: Artem Belov Date: Tue, 4 Nov 2014 00:36:25 +0300 Subject: [PATCH] Added "submenuTemplate" property for "items" config in Menu widget fixes #5681 close #5897 --- framework/CHANGELOG.md | 1 + framework/widgets/Menu.php | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 5b26de2..1c92e17 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -27,6 +27,7 @@ Yii Framework 2 Change Log - Enh #3723: `yii\filters\PageCache` now supports caching response headers as well as non-HTML response content (qiangxue) - Enh #4710: Added `yii\web\AssetManager::appendTimestamp` to support cache busting for assets (qiangxue) - Enh #5663: Added support for using `data-params` to specify additional form data to be submitted via the `data-method` approach (usualdesigner, qiangxue) +- Enh #5681: Allow customization of Menu::submenuTemplate in menu items (RobertBoes, otsec) - Enh #6106: Added ability to specify `encode` for each item of `yii\widgets\Breadcrumbs` (samdark, aleksanderd) - Enh #6361: Added `validateAttribute()` to `yii.activeForm.js` to support manually triggering data validation of an input (Alex-Code, qiang) - Enh #6493: Added support for the `Access-Control-Expose-Headers` header by `yii\filters\Cors` (usualdesigner) diff --git a/framework/widgets/Menu.php b/framework/widgets/Menu.php index 286c8f3..381fc86 100644 --- a/framework/widgets/Menu.php +++ b/framework/widgets/Menu.php @@ -68,6 +68,9 @@ class Menu extends Widget * The token `{url}` will be replaced by the URL associated with this menu item, * and the token `{label}` will be replaced by the label of the menu item. * If this option is not set, [[linkTemplate]] or [[labelTemplate]] will be used instead. + * - submenuTemplate: string, optional, the template used to render the list of sub-menus. + * The token `{items}` will be replaced with the rendered sub-menu items. + * If this option is not set, [[submenuTemplate]] will be used instead. * - options: array, optional, the HTML attributes for the menu container tag. */ public $items = []; @@ -96,7 +99,7 @@ class Menu extends Widget public $labelTemplate = '{label}'; /** * @var string the template used to render a list of sub-menus. - * In this template, the token `{items}` will be replaced with the renderer sub-menu items. + * In this template, the token `{items}` will be replaced with the rendered sub-menu items. */ public $submenuTemplate = "\n\n"; /** @@ -208,7 +211,8 @@ class Menu extends Widget $menu = $this->renderItem($item); if (!empty($item['items'])) { - $menu .= strtr($this->submenuTemplate, [ + $submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate); + $menu .= strtr($submenuTemplate, [ '{items}' => $this->renderItems($item['items']), ]); }