diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 2a5011585a9..a15279e0871 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -199,6 +199,7 @@ class CoreBundle extends Bundle { ->addTag('route_filter'); $container->register('router_processor_subscriber', 'Drupal\Core\EventSubscriber\RouteProcessorSubscriber') + ->addArgument(new Reference('content_negotiation')) ->addTag('event_subscriber'); $container->register('router_listener', 'Symfony\Component\HttpKernel\EventListener\RouterListener') ->addArgument(new Reference('router')) diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php index 61c778848af..006153030db 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php @@ -16,12 +16,19 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Drupal\Core\ContentNegotiation; /** * Listener to process request controller information. */ class RouteProcessorSubscriber implements EventSubscriberInterface { + protected $negotiation; + + public function __construct(ContentNegotiation $negotiation) { + $this->negotiation = $negotiation; + } + /** * Sets a default controller for a route if one was not specified. * @@ -31,7 +38,7 @@ class RouteProcessorSubscriber implements EventSubscriberInterface { public function onRequestSetController(GetResponseEvent $event) { $request = $event->getRequest(); - if (!$request->attributes->has('_controller') && $request->attributes->has('_content')) { + if (!$request->attributes->has('_controller') && $this->negotiation->getContentType($request) === 'html') { $request->attributes->set('_controller', '\Drupal\Core\HtmlPageController::content'); } }