You are here

protected function EntityResource::doPatchIndividualRelationship in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchIndividualRelationship()

Update a to-one relationship.

Parameters

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

\Drupal\jsonapi\JsonApiResource\ResourceIdentifier[] $resource_identifiers: The client-sent resource identifiers which should be set on the given entity. Should be an empty array or an array with a single value.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition of the entity field to be updated.

Throws

\Symfony\Component\HttpKernel\Exception\BadRequestHttpException Thrown when a "to-one" relationship is not provided.

File

core/modules/jsonapi/src/Controller/EntityResource.php, line 700

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected function doPatchIndividualRelationship(EntityInterface $entity, array $resource_identifiers, FieldDefinitionInterface $field_definition) {
  if (count($resource_identifiers) > 1) {
    throw new BadRequestHttpException(sprintf('Provide a single relationship so to-one relationship fields (%s).', $field_definition
      ->getName()));
  }
  $this
    ->doPatchMultipleRelationship($entity, $resource_identifiers, $field_definition);
}