Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment