You are here

protected function EntityResource::doPatchIndividualRelationship in JSON:API 8

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

Update a to-one relationship.

Parameters

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

\Drupal\Core\Field\EntityReferenceFieldItemListInterface $parsed_field_list: The entity reference field list of items to add, or a response object in case of error.

File

src/Controller/EntityResource.php, line 713

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

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