protected function EntityResource::doPatchMultipleRelationship in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchMultipleRelationship()
- 10 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchMultipleRelationship()
Update a to-many 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.
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition of the entity field to be updated.
1 call to EntityResource::doPatchMultipleRelationship()
- EntityResource::doPatchIndividualRelationship in core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Update a to-one relationship.
File
- core/
modules/ jsonapi/ src/ Controller/ EntityResource.php, line 713
Class
- EntityResource
- Process all entity requests.
Namespace
Drupal\jsonapi\ControllerCode
protected function doPatchMultipleRelationship(EntityInterface $entity, array $resource_identifiers, FieldDefinitionInterface $field_definition) {
$main_property_name = $field_definition
->getItemDefinition()
->getMainPropertyName();
$entity->{$field_definition
->getName()} = array_map(function (ResourceIdentifier $resource_identifier) use ($main_property_name) {
$field_properties = [
$main_property_name => $this
->getEntityFromResourceIdentifier($resource_identifier)
->id(),
];
// Remove `arity` from the received extra properties, otherwise this
// will fail field validation.
$field_properties += array_diff_key($resource_identifier
->getMeta(), array_flip([
ResourceIdentifier::ARITY_KEY,
]));
return $field_properties;
}, $resource_identifiers);
}