diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e8cff8b..62f2d6f 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1778,7 +1778,7 @@ function drupal_common_theme() { ), // From menu.inc. 'menu' => array( - 'variables' => array('items' => array(), 'attributes' => array()), + 'variables' => array('menu_name' => NULL, 'items' => array(), 'attributes' => array()), ), 'menu_local_task' => array( 'render element' => 'element', diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index 5b3aee8..3c71930f 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -177,6 +177,7 @@ public function build(array $tree) { // Add the theme wrapper for outer markup. // Allow menu-specific theme overrides. $build['#theme'] = 'menu__' . strtr($menu_name, '-', '_'); + $build['#menu_name'] = $menu_name; $build['#items'] = $items; // Set cache tag. $build['#cache']['tags'][] = 'config:system.menu.' . $menu_name; diff --git a/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php b/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php index ac6af14..d51f6e3 100644 --- a/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php +++ b/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php @@ -135,6 +135,7 @@ public function providerTestBuildCacheability() { 'max-age' => Cache::PERMANENT, ], '#sorted' => TRUE, + '#menu_name' => 'mock', '#theme' => 'menu__mock', '#items' => [ // To be filled when generating test cases, using $get_built_element(). diff --git a/core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php b/core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php index 6742e6c..d1e22a9 100644 --- a/core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php +++ b/core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php @@ -30,6 +30,7 @@ public function build(array $tree, $level = 0) { $menu_name = $first_link->getMenuName(); // Add a more specific theme suggestion to differentiate this rendered // menu from others. + $build['#menu_name'] = $menu_name; $build['#theme'] = 'menu__toolbar__' . strtr($menu_name, '-', '_'); return $build; }