function EntityResource::doPatchIndividualRelationship

Same name in other branches
  1. 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchIndividualRelationship()
  2. 10 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchIndividualRelationship()
  3. 11.x 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 695

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.