diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php index 8c7be11..74dd1be 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php @@ -20,9 +20,9 @@ * Normalizes GET requests performing a redirect if required. * * Not every but most of GET requests are processed. All conditions can be found - * in onKernelRequestRedirect() method. + * in shouldRedirect() method. * - * The normalization can be disabled by setting the "disable_route_normalizer" + * The normalization can be disabled by setting the "_disable_route_normalizer" * request parameter to TRUE. However, this should be done before * onKernelRequestRedirect() method is executed. */ @@ -72,7 +72,7 @@ public function __construct(UrlGeneratorInterface $url_generator, PathMatcherInt * different from the requested one. Examples: * - Language negotiation system detected a language to use, and that language * has a path prefix: perform a redirect to the language prefixed URL. - * - A route that set as the front page is requested: redirect to the front + * - A route that's set as the front page is requested: redirect to the front * page. * - Requested path has an alias: redirect to alias. * @@ -83,13 +83,8 @@ public function onKernelRequestRedirect(GetResponseEvent $event) { if (!$this->config->get('core.routing')->get('route_normalizer.enabled')) { return; } - $request = $event->getRequest(); - $can_redirect = $event->isMasterRequest() - && $request->isMethod('GET') - && !$request->query->has('destination') - && RequestHelper::isCleanUrl($request) - && !$request->attributes->get('disable_route_normalizer'); - if ($can_redirect) { + if ($this->shouldRedirect($event)) { + $request = $event->getRequest(); // The "" placeholder can be used for all routes except the front // page because it's not a real route. $route_name = $this->pathMatcher->isFrontPage() ? '' : ''; @@ -108,12 +103,27 @@ public function onKernelRequestRedirect(GetResponseEvent $event) { } /** + * Detects if a redirect can be performed during the current request. + * + * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event + * The Event to process. + * + * @return bool + */ + protected function shouldRedirect(GetResponseEvent $event) { + return $event->isMasterRequest() + && ($request = $event->getRequest()) + && $request->isMethod('GET') + && !$request->query->has('destination') + && RequestHelper::isCleanUrl($request) + && !$request->attributes->get('_disable_route_normalizer'); + } + + /** * {@inheritdoc} */ static function getSubscribedEvents() { - // Execute after routes are initialized in - // \Drupal\Core\Routing\RoutePreloader::onRequest(). - $events[KernelEvents::REQUEST][] = array('onKernelRequestRedirect', -1); + $events[KernelEvents::REQUEST][] = array('onKernelRequestRedirect'); return $events; } diff --git a/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php b/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php index 48bf809..a9eb34a 100644 --- a/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php +++ b/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php @@ -71,7 +71,7 @@ public function processInbound($path, Request $request) { $request->query->set('file', $file); // Disable route normalizer since we changed the request object. - $request->attributes->set('disable_route_normalizer', TRUE); + $request->attributes->set('_disable_route_normalizer', TRUE); return $path_prefix . $image_style . '/' . $scheme; }