diff --git a/core/core.services.yml b/core/core.services.yml index 868d4ab..9331fa6 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -326,6 +326,10 @@ services: tags: - { name: event_subscriber } arguments: ['@settings'] + ajax_response_subscriber: + class: Drupal\Core\EventSubscriber\AjaxResponseSubscriber + tags: + - { name: event_subscriber } route_enhancer.authentication: class: Drupal\Core\Routing\Enhancer\AuthenticationEnhancer tags: diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php index 7660f77..fb4d494 100644 --- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php @@ -46,17 +46,13 @@ public function addCommand($command, $prepend = FALSE) { } /** - * Sets the response's data to be the array of AJAX commands. + * Sets the rendered ajax ajax right before the response is prepared * - * @param Request $request - * A request object. - * - * @return Response - * The current response. + * @param \Symfony\Component\HttpFoundation\Request $request + * The request object. */ - public function prepare(Request $request) { + public function prepareResponse(Request $request) { $this->setData($this->ajaxRender($request)); - return parent::prepare($request); } /** diff --git a/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php new file mode 100644 index 0000000..cb1ca5d --- /dev/null +++ b/core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php @@ -0,0 +1,39 @@ +getResponse(); + if ($response instanceof AjaxResponse) { + $response->prepareResponse($event->getRequest()); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events[KernelEvents::RESPONSE][] = array('onResponse', -100); + + return $events; + } + +}