- Issue created by @mrjey
- 🇳🇿New Zealand quietone
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies → .
When creating or updating an entity, sometime validators overwrite field values and saving leads to an error.
You can use "data_field" module to reproduce the problem.
Create a new content type with a DataField field type and inside this field a entity reference sub-field to a taxonomy.
When you create a new instance of this entity via JSON:API, you need to submit the tid for the sub-field and you can check that on database table is saved the number 1 (always saves 1 if tid passed is correct), instead of tid number.
This is beacause validator of sibfield loads the taxonomy instance and override the subfield (which has the tid) with the taxonomy object.
A proposed solution is cloning the entity to create/update before validating:
public function createIndividual(ResourceType $resource_type, Request $request) {
...
static::validate(clone $parsed_entity);
...
}
public function patchIndividual(ResourceType $resource_type, EntityInterface $entity, Request $request) {
...
static::validate(clone $entity, $field_names);
...
}
Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies → .