Commit cc93aedb authored by catch's avatar catch
Browse files

Issue #1895984 by sdboyer: Improve new-style controller selection by relying on ContentNegotiation.

parent dcfdede7
......@@ -199,6 +199,7 @@ public function build(ContainerBuilder $container) {
->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'))
......
......@@ -16,12 +16,19 @@
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');
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment