function EntityResource::doPatchMultipleRelationship
Same name and namespace in other branches
- 10 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchMultipleRelationship()
- 11.x core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchMultipleRelationship()
- 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::doPatchMultipleRelationship()
- 8.9.x 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 662
Class
- EntityResource
- Process all entity requests.
Namespace
Drupal\jsonapi\ControllerCode
protected function doPatchMultipleRelationship(EntityInterface $entity, array $resource_identifiers, FieldDefinitionInterface $field_definition) {
// @todo Inject the plugin manager service.
$definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_definition->getType());
$serialized_property_names = $definition['serialized_property_names'] ?? [];
$entity->{$field_definition->getName()} = array_map(function (ResourceIdentifier $resource_identifier) use ($serialized_property_names) {
// We assume all entity reference fields have an 'entity' computed
// property that can be used to assign the needed values.
$field_properties = [
'entity' => $this->getEntityFromResourceIdentifier($resource_identifier),
];
// Remove `arity` from the received extra properties, otherwise this
// will fail field validation.
$meta = array_diff_key($resource_identifier->getMeta(), array_flip([
ResourceIdentifier::ARITY_KEY,
]));
foreach ($serialized_property_names as $property_name) {
if (isset($meta[$property_name]) && is_string($meta[$property_name])) {
throw new BadRequestHttpException(sprintf('The relationship meta field "%s" cannot accept a serialized string value.', $property_name));
}
}
$field_properties += $meta;
return $field_properties;
}, $resource_identifiers);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.