From 790cc4c261d584f219ef25d0cde563a08b7621b9 Mon Sep 17 00:00:00 2001 From: Chi Date: Fri, 24 Apr 2020 10:14:10 +0000 Subject: [PATCH] Add cache keys for drupal_menu() --- src/View/MenuViewBuilder.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/View/MenuViewBuilder.php b/src/View/MenuViewBuilder.php index 23c4b8f..0d439bf 100644 --- a/src/View/MenuViewBuilder.php +++ b/src/View/MenuViewBuilder.php @@ -64,7 +64,19 @@ class MenuViewBuilder { ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'], ]; $tree = $this->menuLinkTree->transform($tree, $manipulators); - return $this->menuLinkTree->build($tree); + $build = $this->menuLinkTree->build($tree); + + if (!isset($build['#cache']['keys'])) { + $build['#cache']['keys'] = [ + 'twig_tweak_menu', + $menu_name, + '[level]=' . $level, + '[depth]=' . $depth, + '[expand]=' . (int) $expand, + ]; + } + + return $build; } }