Issue #1895984 by sdboyer: Improve new-style controller selection by relying on ContentNegotiation.
parent
dcfdede780
commit
cc93aedb71
|
@ -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'))
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue