diff --git a/core/includes/menu.inc b/core/includes/menu.inc index a8a30b6..a9b7d5f 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2607,6 +2607,9 @@ function menu_router_rebuild() { * (optional) Save the new router to the database. Defaults to FALSE. */ function menu_router_build($save = FALSE) { + // Ensure that all configuration used to build the menu items are loaded + // without overrides. + config_context_enter('config.context.free'); // We need to manually call each module so that we can know which module // a given item came from. $callbacks = array(); @@ -2621,6 +2624,8 @@ function menu_router_build($save = FALSE) { } // Alter the menu as defined in modules, keys are like user/%user. drupal_alter('menu', $callbacks); + // Return to the original context before menu building. + config_context_leave(); foreach ($callbacks as $path => $router_item) { // If the menu item is a default local task and incorrectly references a // route, remove it. diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php index 71cf0c4..ec8bdf3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php @@ -623,4 +623,24 @@ protected function doTestThemeCallbackHookCustomTheme() { $this->assertRaw('seven/style.css', "The Seven theme's CSS appears on the page."); } + /** + * Tests the context in menu router rebuild. + */ + public function testMenuRouterRebuildContext() { + // Get the different contexts to ensure that the two services are not the same. + $config_context = \Drupal::service('menu_test.config_context'); + $free_config_context = \Drupal::service('config.context.free'); + $this->assertFalse(spl_object_hash($config_context) === spl_object_hash($free_config_context)); + + // Enter a context before the router rebuild. + config_context_enter('menu_test.config_context'); + menu_router_rebuild(); + + $context_after = \Drupal::service('config.factory')->getContext(); + $this->assertTrue(spl_object_hash($context_after) === spl_object_hash($config_context)); + + $context_inner = \Drupal::state()->get('menu_router_test.config_context'); + $this->assertTrue(spl_object_hash($context_inner) == spl_object_hash($free_config_context)); + } + } diff --git a/core/modules/system/tests/modules/menu_test/menu_test.module b/core/modules/system/tests/modules/menu_test/menu_test.module index ab2ef30..4e614f9 100644 --- a/core/modules/system/tests/modules/menu_test/menu_test.module +++ b/core/modules/system/tests/modules/menu_test/menu_test.module @@ -293,6 +293,8 @@ function menu_test_menu() { 'type' => MENU_LOCAL_TASK, ); + \Drupal::state()->set('menu_router_test.config_context', \Drupal::service('config.factory')->getContext()); + return $items; } diff --git a/core/modules/system/tests/modules/menu_test/menu_test.services.yml b/core/modules/system/tests/modules/menu_test/menu_test.services.yml index 097ddf2..83da8ed 100644 --- a/core/modules/system/tests/modules/menu_test/menu_test.services.yml +++ b/core/modules/system/tests/modules/menu_test/menu_test.services.yml @@ -3,3 +3,9 @@ services: class: Drupal\menu_test\EventSubscriber\MaintenanceModeSubscriber tags: - { name: event_subscriber } + + menu_test.config_context: + class: Drupal\Core\Config\Context\ContextInterface + factory_method: get + factory_service: config.context.factory + arguments: [Drupal\Core\Config\Context\FreeConfigContext]