summaryrefslogtreecommitdiffstats
path: root/src/Normalizer
diff options
context:
space:
mode:
authorflorenttorregrosa2017-06-12 21:10:31 (GMT)
committerMateu Aguiló Bosch2017-06-12 21:10:31 (GMT)
commitdbb3413a1244eb8decb9066f2543a8bc305ee107 (patch)
tree867fdd83e12587f57e73b8c3418fe81c0d4cc78a /src/Normalizer
parent01d63593c10506030a2e37538e24c798a936ddbf (diff)
fix(Enhancers): Fix the prepareForInput application in multiple cardinality fields (#2884862 by Grimreaper, e0ipso)
Diffstat (limited to 'src/Normalizer')
-rw-r--r--src/Normalizer/EntityNormalizerTrait.php19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/Normalizer/EntityNormalizerTrait.php b/src/Normalizer/EntityNormalizerTrait.php
index 1cd343d..4ebc6d1 100644
--- a/src/Normalizer/EntityNormalizerTrait.php
+++ b/src/Normalizer/EntityNormalizerTrait.php
@@ -21,6 +21,11 @@ trait EntityNormalizerTrait {
* The modified input data.
*/
protected function prepareInput(array $data, ResourceType $resource_type) {
+ /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions */
+ $field_storage_definitions = \Drupal::service('entity_field.manager')
+ ->getFieldStorageDefinitions(
+ $resource_type->getEntityTypeId()
+ );
$data_internal = [];
/** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */
// Translate the public fields into the entity fields.
@@ -31,7 +36,19 @@ trait EntityNormalizerTrait {
}
$internal_name = $resource_type->getInternalName($public_field_name);
$enhancer = $resource_type->getFieldEnhancer($public_field_name, 'publicName');
- $field_value = $enhancer ? $enhancer->prepareForInput($field_value) : $field_value;
+
+ if (isset($field_storage_definitions[$internal_name])) {
+ $field_storage_definition = $field_storage_definitions[$internal_name];
+ if ($field_storage_definition->getCardinality() === 1) {
+ $field_value = $enhancer ? $enhancer->prepareForInput($field_value) : $field_value;
+ }
+ else {
+ foreach ($field_value as $key => $individual_field_value) {
+ $field_value[$key] = $enhancer ? $enhancer->prepareForInput($individual_field_value) : $individual_field_value;
+ }
+ }
+ }
+
$data_internal[$internal_name] = $field_value;
}