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;
} /**
* Adds a relationship to a to-many relationship.
*
* @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type
* The base JSON:API resource type for the request to be served.
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* The requested entity.
* @param string $related
* The related field name.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @return \Drupal\jsonapi\ResourceResponse
* The response.
*
* @throws \Drupal\jsonapi\Exception\EntityAccessDeniedHttpException
* Thrown when the current user is not allowed to PATCH the selected
* field(s).
* @throws \Symfony\Component\HttpKernel\Exception\ConflictHttpException
* Thrown when POSTing to a "to-one" relationship.
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown when the underlying entity cannot be saved.
* @throws \Drupal\jsonapi\Exception\UnprocessableHttpEntityException
* Thrown when the updated entity does not pass validation.
*/