diff --git a/core/lib/Drupal/Core/Ajax/AjaxSubscriber.php b/core/lib/Drupal/Core/Ajax/AjaxSubscriber.php new file mode 100644 index 0000000..7d2ed7b --- /dev/null +++ b/core/lib/Drupal/Core/Ajax/AjaxSubscriber.php @@ -0,0 +1,41 @@ +getRequest(); + $request->setFormat('ajax', 'application/vnd.drupal-ajax'); + } + + /** + * Registers the methods in this class that should be listeners. + * + * @return array + * An array of event listener definitions. + */ + static function getSubscribedEvents(){ + $events[KernelEvents::REQUEST][] = array('onKernelRequest', 50); + return $events; + } + +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php index 1695de9..5dfefc2 100644 --- a/core/lib/Drupal/Core/ContentNegotiation.php +++ b/core/lib/Drupal/Core/ContentNegotiation.php @@ -36,16 +36,11 @@ public function getContentType(Request $request) { return 'iframeupload'; } - // AJAX calls need to be run through ajax rendering functions - elseif ($request->isXmlHttpRequest()) { - return 'ajax'; - } - // Check all formats, it HTML is found return it. $first_found_format = FALSE; foreach ($request->getAcceptableContentTypes() as $mime_type) { $format = $request->getFormat($mime_type); - if ($format === 'html') { + if ($format === 'html' || $format === 'ajax') { return $format; } if (!is_null($format) && !$first_found_format) { diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 6f7ff31..2f770a8 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -301,6 +301,10 @@ public function build(ContainerBuilder $container) { $container->register('plugin.manager.condition', 'Drupal\Core\Condition\ConditionManager'); + // Register Ajax event subscriber. + $container->register('ajax.subscriber', 'Drupal\Core\Ajax\AjaxSubscriber') + ->addTag('event_subscriber'); + $container->addCompilerPass(new RegisterMatchersPass()); $container->addCompilerPass(new RegisterRouteFiltersPass()); // Add a compiler pass for registering event subscribers. diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php index 9eb2c3c..58387b2 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php @@ -37,8 +37,7 @@ public function __construct(ContentNegotiation $negotiation) { */ public function onRequestSetController(GetResponseEvent $event) { $request = $event->getRequest(); - - if (in_array('application/vnd.drupal-ajax', $request->getAcceptableContentTypes()) && !$request->attributes->has('_content')) { + if (!$request->attributes->has('_content') && $this->negotiation->getContentType($request) == 'ajax') { $request->attributes->set('_content', $request->attributes->get('_controller')); $request->attributes->set('_controller', '\Drupal\Core\AjaxController::content'); }