You are here

public function EntityResource::getRelationship in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getRelationship()

Gets the relationship of an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The requested entity.

string $related_field: 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.

3 calls to EntityResource::getRelationship()
EntityResource::createRelationship in src/Controller/EntityResource.php
Adds a relationship to a to-many relationship.
EntityResource::deleteRelationship in src/Controller/EntityResource.php
Deletes the relationship of an entity.
EntityResource::patchRelationship in src/Controller/EntityResource.php
Updates the relationship of an entity.

File

src/Controller/EntityResource.php, line 532

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

public function getRelationship(EntityInterface $entity, $related_field, Request $request, $response_code = 200) {
  $related_field = $this->resourceType
    ->getInternalName($related_field);
  $this
    ->relationshipAccess($entity, 'view', $related_field);

  /* @var \Drupal\Core\Field\FieldItemListInterface $field_list */
  $field_list = $entity
    ->get($related_field);
  $this
    ->validateReferencedResource($field_list, $related_field);
  $response = $this
    ->buildWrappedResponse($field_list, $response_code);
  return $response;
}