Item active Closure on yii\widgets\Menu always return true

Hi there!

I have noticed this strange behavior while building a Menu on a View: I wanted to keep a menu item active also for other routes as well as for its own route, according to the documentation I have implemented a closure for the active key in this way:




...

<?=

Menu::widget([

  'options' => [

    'class' => 'nav nav-pills nav-stacked'

  ],

  'items' => [

    ['label' => Yii::t('user', 'Profile'), 'url' => ['/user/settings/profile']],

    ['label' => Yii::t('user', 'Account'), 'url' => ['/user/settings/account']],

    ['label' => 'My Orders', 'url' => ['/orders/confirmed'],

      'active' => function ($item, $hasActiveChild, $isItemActive, $widget) {

    return ArrayHelper::isIn(\Yii::$app->requestedRoute, ['orders/confirmed', 'orders/completed', 'orders/old']);

  }

    ]

  ]

])

?>

...



However the result is that the menu item is always active, whereas returning a boolean, without using the Closure, everything work correctly:




...

'active' => ArrayHelper::isIn(\Yii::$app->requestedRoute, ['orders/confirmed', 'orders/completed', 'orders/old']),

    ],

...



I have solved my problem but I was wondering why the Closure approach did not work… may I implemented it wrongly or could it be a bug?

Closure support was added in 2.0.11 which isn’t yet released.