Issue #2329303 by tim.plunkett, dawehner: Fixed Use the right request when determining the theme on a 403 page.

8.0.x
webchick 2014-08-28 14:41:59 -07:00
parent 2191f864ab
commit 469fe97e00
4 changed files with 68 additions and 2 deletions

View File

@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
/** /**
* Default object for current_route_match service. * Default object for current_route_match service.
*/ */
class CurrentRouteMatch implements RouteMatchInterface { class CurrentRouteMatch implements RouteMatchInterface, StackedRouteMatchInterface {
/** /**
* The related request stack. * The related request stack.
@ -88,7 +88,7 @@ class CurrentRouteMatch implements RouteMatchInterface {
* @return \Drupal\Core\Routing\RouteMatchInterface * @return \Drupal\Core\Routing\RouteMatchInterface
* The current route match object. * The current route match object.
*/ */
protected function getCurrentRouteMatch() { public function getCurrentRouteMatch() {
return $this->getRouteMatch($this->requestStack->getCurrentRequest()); return $this->getRouteMatch($this->requestStack->getCurrentRequest());
} }
@ -118,4 +118,18 @@ class CurrentRouteMatch implements RouteMatchInterface {
return $route_match; return $route_match;
} }
/**
* {@inheritdoc}
*/
public function getMasterRouteMatch() {
return $this->getRouteMatch($this->requestStack->getMasterRequest());
}
/**
* {@inheritdoc}
*/
public function getParentRouteMatch() {
return $this->getRouteMatch($this->requestStack->getParentRequest());
}
} }

View File

@ -0,0 +1,40 @@
<?php
/**
* @file
* Contains \Drupal\Core\Routing\StackedRouteMatchInterface.
*/
namespace Drupal\Core\Routing;
/**
* Defines an interface for a stack of route matches.
*
* This could be for example used on exception pages.
*/
interface StackedRouteMatchInterface extends RouteMatchInterface {
/**
* Gets the current route match.
*
* @return \Drupal\Core\Routing\RouteMatchInterface
*/
public function getCurrentRouteMatch();
/**
* Gets the master route match..
*
* @return \Drupal\Core\Routing\RouteMatchInterface
*/
public function getMasterRouteMatch();
/**
* Returns the parent route match of the current.
*
* @return \Drupal\Core\Routing\RouteMatchInterface\NULL
* The parent route match or NULL, if it the master route match.
*/
public function getParentRouteMatch();
}

View File

@ -9,6 +9,7 @@ namespace Drupal\Core\Theme;
use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\StackedRouteMatchInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
/** /**
@ -124,6 +125,9 @@ class ThemeManager implements ThemeManagerInterface {
if (!$route_match) { if (!$route_match) {
$route_match = \Drupal::routeMatch(); $route_match = \Drupal::routeMatch();
} }
if ($route_match instanceof StackedRouteMatchInterface) {
$route_match = $route_match->getMasterRouteMatch();
}
$theme = $this->themeNegotiator->determineActiveTheme($route_match); $theme = $this->themeNegotiator->determineActiveTheme($route_match);
$this->activeTheme = $this->themeInitialization->initTheme($theme); $this->activeTheme = $this->themeInitialization->initTheme($theme);
} }

View File

@ -209,6 +209,14 @@ class ThemeTest extends WebTestBase {
$this->drupalGet('admin/config'); $this->drupalGet('admin/config');
$this->assertRaw('core/themes/seven', 'Administration theme used on an administration page.'); $this->assertRaw('core/themes/seven', 'Administration theme used on an administration page.');
// Ensure that the admin theme is also visible on the 403 page.
$normal_user = $this->drupalCreateUser(['view the administration theme']);
$this->drupalLogin($normal_user);
$this->drupalGet('admin/config');
$this->assertResponse(403);
$this->assertRaw('core/themes/seven', 'Administration theme used on an administration page.');
$this->drupalLogin($this->admin_user);
$this->drupalGet('node/add'); $this->drupalGet('node/add');
$this->assertRaw('core/themes/stark', 'Site default theme used on the add content page.'); $this->assertRaw('core/themes/stark', 'Site default theme used on the add content page.');