From 4803620832ae786bed743448de02ac7a013b7676 Mon Sep 17 00:00:00 2001 From: George Potter <53481-gpotter@users.noreply.drupalcode.org> Date: Fri, 23 Sep 2022 20:33:34 +0500 Subject: [PATCH] Issue #3222666 by gpotter, theRuslan, Chi, smustgrave, superbiche, letrollpoilu: drupal_menu() incorrectly caches the active parent menu item in two-leveled menu --- src/TwigExtension.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/TwigExtension.php b/src/TwigExtension.php index 52e8711..9ed9abc 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -716,7 +716,7 @@ class TwigExtension extends AbstractExtension { $parameters->setMinDepth($level); // When the depth is configured to zero, there is no depth limit. When depth // is non-zero, it indicates the number of levels that must be displayed. - // Hence this is a relative depth that we must convert to an actual + // Hence, this is a relative depth that we must convert to an actual // (absolute) depth, that may never exceed the maximum depth. if ($depth > 0) { $parameters->setMaxDepth(min($level + $depth - 1, $menu_tree->maxDepth())); @@ -733,7 +733,10 @@ class TwigExtension extends AbstractExtension { ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'], ]; $tree = $menu_tree->transform($tree, $manipulators); - return $menu_tree->build($tree); + $build = $menu_tree->build($tree); + + $build['#cache']['contexts'][] = 'route.menu_active_trails:' . $menu_name; + return $build; } /**