public function onResponse(ResponseEvent
$event) { $response =
$event->
getResponse();
if (!
$response instanceof ResourceResponse
) { return;
} $request =
$event->
getRequest();
$format = 'api_json';
$this->
renderResponseBody($request,
$response,
$this->serializer,
$format);
$event->
setResponse($this->
flattenResponse($response,
$request));
} /**
* Renders a resource response body.
*
* Serialization can invoke rendering (e.g., generating URLs), but the
* serialization API does not provide a mechanism to collect the
* bubbleable metadata associated with that (e.g., language and other
* contexts), so instead, allow those to "leak" and collect them here in
* a render context.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param \Drupal\jsonapi\ResourceResponse $response
* The response from the JSON:API resource.
* @param \Symfony\Component\Serializer\SerializerInterface $serializer
* The serializer to use.
* @param string|null $format
* The response format, or NULL in case the response does not need a format,
* for example for the response to a DELETE request.
*
* @todo Add test coverage for language negotiation contexts in
* https://www.drupal.org/node/2135829.
*/