From 4afbad1aae2d0f2873ae2e5fd6333c1eb7d643be Mon Sep 17 00:00:00 2001 From: voskobovich Date: Mon, 28 Dec 2015 13:01:12 +0200 Subject: [PATCH] Calculation of activity menu item through the closure Extended documentation --- framework/widgets/Menu.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/widgets/Menu.php b/framework/widgets/Menu.php index 32d8dd2..19a76e8 100644 --- a/framework/widgets/Menu.php +++ b/framework/widgets/Menu.php @@ -60,7 +60,8 @@ class Menu extends Widget * otherwise, [[labelTemplate]] will be used. * - visible: boolean, optional, whether this menu item is visible. Defaults to true. * - items: array, optional, specifies the sub-menu items. Its format is the same as the parent items. - * - active: boolean, optional, whether this menu item is in active state (currently selected). + * - active: boolean or closure that returns boolean, optional, whether this menu item is in active state (currently selected). + * When using a closure, its signature should be `function ($item, $hasActiveChild, $widget)`. * If a menu item is active, its CSS class will be appended with [[activeCssClass]]. * If this option is not set, the menu item will be set active automatically when the current request * is triggered by `url`. For more details, please refer to [[isItemActive()]]. @@ -285,6 +286,8 @@ class Menu extends Widget } else { $items[$i]['active'] = false; } + } elseif ($item['active'] instanceof \Closure) { + $active = $items[$i]['active'] = call_user_func($item['active'], $item, $hasActiveChild, $this); } elseif ($item['active']) { $active = true; }