protected function EntityResource::buildWrappedResponse in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::buildWrappedResponse()
Builds a response with the appropriate wrapped document.
Parameters
\Drupal\jsonapi\JsonApiResource\TopLevelDataInterface $data: The data to wrap.
\Symfony\Component\HttpFoundation\Request $request: The request object.
\Drupal\jsonapi\JsonApiResource\IncludedData $includes: The resources to be included in the document. Use NullData if there should be no included resources in the document.
int $response_code: The response code.
array $headers: An array of response headers.
\Drupal\jsonapi\JsonApiResource\LinkCollection $links: The URLs to which to link. A 'self' link is added automatically.
array $meta: (optional) The top-level metadata.
Return value
\Drupal\jsonapi\ResourceResponse The response.
6 calls to EntityResource::buildWrappedResponse()
- EntityResource::createIndividual in core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Creates an individual entity.
- EntityResource::getIndividual in core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Gets the individual entity.
- EntityResource::getRelated in core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Gets the related resource.
- EntityResource::getRelationship in core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Gets the relationship of an entity.
- EntityResource::patchIndividual in core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Patches an individual entity.
File
- core/
modules/ jsonapi/ src/ Controller/ EntityResource.php, line 991
Class
- EntityResource
- Process all entity requests.
Namespace
Drupal\jsonapi\ControllerCode
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);
}
$response = new ResourceResponse(new JsonApiDocumentTopLevel($data, $includes, $links, $meta), $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;
}