public function ViewSubscriber::onAjax

File

drupal/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php, line 99
Definition of Drupal\Core\EventSubscriber\ViewSubscriber.

Class

ViewSubscriber
Main subscriber for VIEW HTTP responses.

Namespace

Drupal\Core\EventSubscriber

Code

public function onAjax(GetResponseForControllerResultEvent $event) {
  $page_callback_result = $event
    ->getControllerResult();

  // Construct the response content from the page callback result.
  $commands = ajax_prepare_response($page_callback_result);
  $json = ajax_render($commands);

  // Build the actual response object.
  $response = new JsonResponse();
  $response
    ->setContent($json);
  return $response;
}