You are here

public function ResourceResponseSubscriber::onResponse in Drupal 10

Same name in this branch
  1. 10 core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::onResponse()
  2. 10 core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\rest\EventSubscriber\ResourceResponseSubscriber::onResponse()
Same name and namespace in other branches
  1. 8 core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\rest\EventSubscriber\ResourceResponseSubscriber::onResponse()
  2. 9 core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\rest\EventSubscriber\ResourceResponseSubscriber::onResponse()

Serializes ResourceResponse responses' data, and removes that data.

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $event: The event to process.

File

core/modules/rest/src/EventSubscriber/ResourceResponseSubscriber.php, line 67

Class

ResourceResponseSubscriber
Response subscriber that serializes and removes ResourceResponses' data.

Namespace

Drupal\rest\EventSubscriber

Code

public function onResponse(ResponseEvent $event) {
  $response = $event
    ->getResponse();
  if (!$response instanceof ResourceResponseInterface) {
    return;
  }
  $request = $event
    ->getRequest();
  $format = $this
    ->getResponseFormat($this->routeMatch, $request);
  $this
    ->renderResponseBody($request, $response, $this->serializer, $format);
  $event
    ->setResponse($this
    ->flattenResponse($response));
}