public function ResourceResponseSubscriber::onResponse in JSON:API 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::onResponse()
Serializes ResourceResponse responses' data, and removes that data.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event to process.
File
- src/
EventSubscriber/ ResourceResponseSubscriber.php, line 73
Class
- ResourceResponseSubscriber
- Response subscriber that serializes and removes ResourceResponses' data.
Namespace
Drupal\jsonapi\EventSubscriberCode
public function onResponse(FilterResponseEvent $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));
}