diff --git a/core/config/install/core.routing.yml b/core/config/install/core.routing.yml new file mode 100644 index 0000000..e6566b9 --- /dev/null +++ b/core/config/install/core.routing.yml @@ -0,0 +1,2 @@ +route_normalizer: + enabled: true diff --git a/core/config/schema/core.routing.schema.yml b/core/config/schema/core.routing.schema.yml new file mode 100644 index 0000000..ffd5d52 --- /dev/null +++ b/core/config/schema/core.routing.schema.yml @@ -0,0 +1,11 @@ +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 e1fb11f..bc7d60e 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -784,7 +784,7 @@ services: - { name: event_subscriber } route_normalizer_request_subscriber: class: Drupal\Core\EventSubscriber\RouteNormalizerRequestSubscriber - arguments: ['@url_generator', '@path.matcher'] + arguments: ['@url_generator', '@path.matcher', '@config.factory'] 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 163e8d5..8c7be11 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouteNormalizerRequestSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Routing\RequestHelper; use Drupal\Core\Routing\UrlGeneratorInterface; @@ -42,16 +43,26 @@ class RouteNormalizerRequestSubscriber implements EventSubscriberInterface { protected $pathMatcher; /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $config; + + /** * Constructs a RouteNormalizerRequestSubscriber object. * * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * 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. */ - public function __construct(UrlGeneratorInterface $url_generator, PathMatcherInterface $path_matcher) { + public function __construct(UrlGeneratorInterface $url_generator, PathMatcherInterface $path_matcher, ConfigFactoryInterface $config_factory) { $this->urlGenerator = $url_generator; $this->pathMatcher = $path_matcher; + $this->config = $config_factory; } /** @@ -69,6 +80,9 @@ 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; + } $request = $event->getRequest(); $can_redirect = $event->isMasterRequest() && $request->isMethod('GET')