public function EntityResource::getRelationship in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getRelationship()
- 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getRelationship()
Gets the relationship of an entity.
Parameters
\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The base JSON:API resource type for the request to be served.
\Drupal\Core\Entity\FieldableEntityInterface $entity: The requested entity.
string $related: The related field name.
\Symfony\Component\HttpFoundation\Request $request: The request object.
int $response_code: The response code. Defaults to 200.
Return value
\Drupal\jsonapi\ResourceResponse The response.
File
- core/
modules/ jsonapi/ src/ Controller/ EntityResource.php, line 582
Class
- EntityResource
- Process all entity requests.
Namespace
Drupal\jsonapi\ControllerCode
public function getRelationship(ResourceType $resource_type, FieldableEntityInterface $entity, $related, Request $request, $response_code = 200) {
/** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $field_list */
$field_list = $entity
->get($resource_type
->getInternalName($related));
// Access will have already been checked by the RelationshipRouteAccessCheck
// service, so we don't need to call ::getAccessCheckedResourceObject().
$resource_object = ResourceObject::createFromEntity($resource_type, $entity);
$relationship = Relationship::createFromEntityReferenceField($resource_object, $field_list);
$response = $this
->buildWrappedResponse($relationship, $request, $this
->getIncludes($request, $resource_object), $response_code);
// Add the host entity as a cacheable dependency.
if ($response instanceof CacheableResponseInterface) {
$response
->addCacheableDependency($entity);
}
return $response;
}