diff --git a/core/config/install/core.routing.yml b/core/config/install/core.routing.yml deleted file mode 100644 index e6566b9..0000000 --- a/core/config/install/core.routing.yml +++ /dev/null @@ -1,2 +0,0 @@ -route_normalizer: - enabled: true diff --git a/core/config/schema/core.routing.schema.yml b/core/config/schema/core.routing.schema.yml deleted file mode 100644 index ffd5d52..0000000 --- a/core/config/schema/core.routing.schema.yml +++ /dev/null @@ -1,11 +0,0 @@ -core.routing: - type: config_object - label: 'Routing system settings' - mapping: - route_normalizer: - type: mapping - label: 'Route normalizer settings' - mapping: - enabled: - type: boolean - label: 'Enabled' diff --git a/core/core.services.yml b/core/core.services.yml index 3114bc2..32b5eff 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -33,6 +33,7 @@ parameters: - sftp - webcal - rtsp + route_normalizer_enabled: true services: # Simple cache contexts, directly derived from the request context. cache_context.ip: @@ -790,7 +791,7 @@ services: - { name: event_subscriber } route_normalizer_request_subscriber: class: Drupal\Core\EventSubscriber\RouteNormalizerRequestSubscriber - arguments: ['@url_generator', '@path.matcher', '@config.factory'] + arguments: ['@url_generator', '@path.matcher', '%route_normalizer_enabled%'] tags: - { name: event_subscriber } url_generator.non_bubbling: diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php index 74dd1be..129d515 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php @@ -7,7 +7,6 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Routing\RequestHelper; use Drupal\Core\Routing\UrlGeneratorInterface; @@ -43,11 +42,11 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface { protected $pathMatcher; /** - * The config factory. + * The value of the route_normalizer_enabled container parameter. * - * @var \Drupal\Core\Config\ConfigFactoryInterface + * @var bool */ - protected $config; + protected $routeNormalizerEnabled; /** * Constructs a RouteNormalizerRequestSubscriber object. @@ -56,13 +55,13 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface { * The URL generator service. * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher * The path matcher service. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. + * @param bool $route_normalizer_enabled + * The value of the route_normalizer_enabled container parameter. */ - public function __construct(UrlGeneratorInterface $url_generator, PathMatcherInterface $path_matcher, ConfigFactoryInterface $config_factory) { + public function __construct(UrlGeneratorInterface $url_generator, PathMatcherInterface $path_matcher, $route_normalizer_enabled) { $this->urlGenerator = $url_generator; $this->pathMatcher = $path_matcher; - $this->config = $config_factory; + $this->routeNormalizerEnabled = $route_normalizer_enabled; } /** @@ -80,9 +79,6 @@ public function __construct(UrlGeneratorInterface $url_generator, PathMatcherInt * The Event to process. */ public function onKernelRequestRedirect(GetResponseEvent $event) { - if (!$this->config->get('core.routing')->get('route_normalizer.enabled')) { - return; - } if ($this->shouldRedirect($event)) { $request = $event->getRequest(); // The "" placeholder can be used for all routes except the front @@ -111,7 +107,8 @@ public function onKernelRequestRedirect(GetResponseEvent $event) { * @return bool */ protected function shouldRedirect(GetResponseEvent $event) { - return $event->isMasterRequest() + return $this->routeNormalizerEnabled + && $event->isMasterRequest() && ($request = $event->getRequest()) && $request->isMethod('GET') && !$request->query->has('destination') diff --git a/core/modules/path/src/Tests/PathAliasTest.php b/core/modules/path/src/Tests/PathAliasTest.php index 98d0fdf..188d4ad 100644 --- a/core/modules/path/src/Tests/PathAliasTest.php +++ b/core/modules/path/src/Tests/PathAliasTest.php @@ -39,13 +39,10 @@ protected function setUp() { */ function testPathCache() { - // Since we have the route normalizer, all GET requests having path aliases - // are redirected directly to that aliases, and no "preload-paths:" cache is - // set. - // @todo Decide whether the caching functionality of - // \Drupal\Core\Path\AliasManager should be removed/updated and whether this - // test should be removed/updated. - return; + // Disable the route normalizer, because otherwise internal paths are + // redirected to their aliases and no "preload-paths:" cache is set. + $this->setContainerParameter('route_normalizer_enabled', FALSE); + $this->rebuildContainer(); // Create test node. $node1 = $this->drupalCreateNode(); diff --git a/sites/default/default.services.yml b/sites/default/default.services.yml index 23f6483..42f76cb 100644 --- a/sites/default/default.services.yml +++ b/sites/default/default.services.yml @@ -153,3 +153,6 @@ parameters: - sftp - webcal - rtsp + # Enables the route normalizer. + # @default true + route_normalizer_enabled: true