diff -u b/core/core.services.yml b/core/core.services.yml --- b/core/core.services.yml +++ b/core/core.services.yml @@ -174,7 +174,7 @@ class: Drupal\Core\Theme\DefaultNegotiator arguments: ['@config.factory'] tags: - - { name: theme_negotiator, priority: 100 } + - { name: theme_negotiator, priority: -100 } theme.negotiator.ajax_base_page: class: Drupal\Core\Theme\AjaxBasePageNegotiator arguments: ['@csrf_token'] diff -u b/core/includes/theme.inc b/core/includes/theme.inc --- b/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -94,11 +94,11 @@ drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); - // Only select the user selected theme if it is available in the - // list of themes that can be accessed. $themes = list_themes(); // @todo Let the theme.negotiator listen to the kernel request event. + // Determine the active theme for the theme negotiator service. This includes + // the default theme as well as really specific ones like the ajax base theme. $request = \Drupal::request(); $theme = \Drupal::service('theme.negotiator')->determineActiveTheme($request) ?: 'stark'; diff -u b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php --- b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php @@ -54,6 +54,7 @@ */ static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = array('onKernelRequestLegacy', 90); + // Initialize the theme system after the routing system. $events[KernelEvents::REQUEST][] = array('onKernelRequestLegacyAfterRouting', 30); return $events; diff -u b/core/lib/Drupal/Core/Theme/ThemeNegotiator.php b/core/lib/Drupal/Core/Theme/ThemeNegotiator.php --- b/core/lib/Drupal/Core/Theme/ThemeNegotiator.php +++ b/core/lib/Drupal/Core/Theme/ThemeNegotiator.php @@ -122,13 +122,12 @@ */ public function determineActiveTheme(Request $request) { foreach ($this->getSortedNegotiators() as $negotiator) { - if (($active_theme = $negotiator->determineActiveTheme($request))) { - if ($this->themeAccess->checkAccess($active_theme)) { - $request->attributes->set('_theme_active', $active_theme); - } + $theme = $negotiator->determineActiveTheme($request); + if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) { + $request->attributes->set('_theme_active', $theme); + return $request->attributes->get('_theme_active'); } } - return $request->attributes->get('_theme_active'); } } diff -u b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php @@ -536,16 +536,6 @@ } /** - * Test that the theme negotiation is properly inherited. - */ - protected function doTestThemeCallbackInheritance() { - theme_enable(array($this->admin_theme)); - $this->drupalGet('menu-test/theme-callback/use-admin-theme/inheritance'); - $this->assertText('Active theme: seven. Actual theme: seven. Theme negotiation inheritance is being tested.', 'Theme negotiation inheritance correctly uses the administrative theme.'); - $this->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page."); - } - - /** * Test the theme negotiation when the site is in maintenance mode. */ protected function doTestThemeCallbackMaintenanceMode() { diff -u b/core/modules/system/system.services.yml b/core/modules/system/system.services.yml --- b/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -31 +31 @@ - - { name: theme_negotiator, priority: 40 } + - { name: theme_negotiator, priority: -40 } diff -u b/core/modules/user/user.services.yml b/core/modules/user/user.services.yml --- b/core/modules/user/user.services.yml +++ b/core/modules/user/user.services.yml @@ -31,3 +31,3 @@ tags: - - { name: theme_negotiator, priority: 50 } + - { name: theme_negotiator, priority: -50 } diff -u b/core/tests/Drupal/Tests/Core/Theme/ThemeNegotiatorTest.php b/core/tests/Drupal/Tests/Core/Theme/ThemeNegotiatorTest.php --- b/core/tests/Drupal/Tests/Core/Theme/ThemeNegotiatorTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/ThemeNegotiatorTest.php @@ -82,14 +82,13 @@ ->method('determineActiveTheme') ->will($this->returnValue('example_test')); - $this->themeNegotiator->addNegotiator($negotiator, 0); + $this->themeNegotiator->addNegotiator($negotiator, 10); $negotiator = $this->getMock('Drupal\Core\Theme\ThemeNegotiatorInterface'); - $negotiator->expects($this->once()) - ->method('determineActiveTheme') - ->will($this->returnValue('example_test2')); + $negotiator->expects($this->never()) + ->method('determineActiveTheme'); - $this->themeNegotiator->addNegotiator($negotiator, 10); + $this->themeNegotiator->addNegotiator($negotiator, 0); $this->themeAccessCheck->expects($this->any()) ->method('checkAccess') @@ -113,24 +112,24 @@ ->method('determineActiveTheme') ->will($this->returnValue('example_test')); - $this->themeNegotiator->addNegotiator($negotiator, 0); + $this->themeNegotiator->addNegotiator($negotiator, 10); $negotiator = $this->getMock('Drupal\Core\Theme\ThemeNegotiatorInterface'); $negotiator->expects($this->once()) ->method('determineActiveTheme') ->will($this->returnValue('example_test2')); - $this->themeNegotiator->addNegotiator($negotiator, 10); + $this->themeNegotiator->addNegotiator($negotiator, 0); $this->themeAccessCheck->expects($this->at(0)) ->method('checkAccess') - ->with('example_test2') - ->will($this->returnValue(TRUE)); + ->with('example_test') + ->will($this->returnValue(FALSE)); $this->themeAccessCheck->expects($this->at(1)) ->method('checkAccess') - ->with('example_test') - ->will($this->returnValue(FALSE)); + ->with('example_test2') + ->will($this->returnValue(TRUE)); $request = Request::create('/test-route'); $theme = $this->themeNegotiator->determineActiveTheme($request);