protected function buildWrappedResponse(TopLevelDataInterface
$data, Request
$request, IncludedData
$includes,
$response_code = 200, array
$headers =
[], LinkCollection
$links = NULL, array
$meta =
[]) { $links =
($links ?:
new LinkCollection([]));
if (!
$links->
hasLinkWithKey('self'
)) { $self_link =
new Link(new CacheableMetadata(), self::
getRequestLink($request), 'self'
);
$links =
$links->
withLink('self',
$self_link);
} $document =
new JsonApiDocumentTopLevel($data,
$includes,
$links,
$meta);
if (!
$request->
isMethodCacheable()) { return new ResourceResponse($document,
$response_code,
$headers);
} $response =
new CacheableResourceResponse($document,
$response_code,
$headers);
$cacheability =
(new CacheableMetadata())->
addCacheContexts([ // Make sure that different sparse fieldsets are cached differently.
'url.query_args:fields',
// Make sure that different sets of includes are cached differently.
'url.query_args:include',
]);
$response->
addCacheableDependency($cacheability);
return $response;
} /**
* Respond with an entity collection.
*
* @param \Drupal\jsonapi\JsonApiResource\ResourceObjectData $primary_data
* The collection of entities.
* @param \Drupal\jsonapi\JsonApiResource\IncludedData|\Drupal\jsonapi\JsonApiResource\NullIncludedData $includes
* The resources to be included in the document.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type
* The base JSON:API resource type for the request to be served.
* @param \Drupal\jsonapi\Query\OffsetPage $page_param
* The pagination parameter for the requested collection.
*
* @return \Drupal\jsonapi\ResourceResponse
* The response.
*/