You are here

protected function EntityResource::validateReferencedResource in JSON:API 8

Validates that the referenced field points to an enabled resource.

Parameters

\Drupal\Core\Field\EntityReferenceFieldItemListInterface|null $field_list: The field list with the reference.

string $related_field: The internal name of the related field.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException If the field is not a reference or the target resource is disabled.

\Symfony\Component\HttpKernel\Exception\HttpException If the $field_list is of the incorrect type.

2 calls to EntityResource::validateReferencedResource()
EntityResource::getRelated in src/Controller/EntityResource.php
Gets the related resource.
EntityResource::getRelationship in src/Controller/EntityResource.php
Gets the relationship of an entity.

File

src/Controller/EntityResource.php, line 555

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected function validateReferencedResource($field_list, $related_field) {
  if (!is_null($field_list) && !$field_list instanceof EntityReferenceFieldItemListInterface) {
    throw new HttpException(500, 'Invalid internal structure for relationship field list.');
  }
  if (!$field_list || !$this
    ->isRelationshipField($field_list)) {
    throw new NotFoundHttpException(sprintf('The relationship %s is not present in this resource.', $related_field));
  }
}