diff -u b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php --- b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php @@ -157,22 +157,29 @@ */ public function getProperties($include_computed = FALSE) { $properties = []; + $property_definitions = $this->definition->getPropertyDefinitions(); + if (!empty($property_definitions)) { + foreach ($property_definitions as $name => $definition) { + if ($include_computed || !$definition->isComputed()) { + $properties[$name] = $this->get($name); + } + } + } // If module creator send an array to map dataType and don't define setPropertyDefinition, // Auto creating the PropertyDefinition so that it can be normalized - $property_definitions = $this->definition->getPropertyDefinitions(); - if (empty($property_definitions) && get_class($this->getDataDefinition()) == 'Drupal\Core\TypedData\MapDataDefinition') { - $values = $this->getValue(); + elseif (get_class($this->getDataDefinition()) == 'Drupal\Core\TypedData\MapDataDefinition') { + $values = $this->values; if (is_array($values)) { foreach ($values as $key => $value) { if (!empty($value) && is_array($value)) { - $data = \Drupal::typedDataManager()->create( + $properties[$key] = \Drupal::typedDataManager()->create( MapDataDefinition::create(), $value, $key ); } else { - $data = \Drupal::typedDataManager()->create( + $properties[$key] = \Drupal::typedDataManager()->create( // Give array's value a DataType,So that drupal can find which normalizer to be used to normalize it // Because we don't know the type of the value,so we use 'any', // If you don't want to use 'any',Please define it by yourself use setPropertyDefinition @@ -181,13 +188,7 @@ $key ); } - $this->definition->setPropertyDefinition($key, $data->getDataDefinition()); - } - } - } - foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { - if ($include_computed || !$definition->isComputed()) { - $properties[$name] = $this->get($name); + }; } } diff -u b/core/tests/Drupal/Tests/Core/TypedData/MapDataNormalizeTest.php b/core/tests/Drupal/Tests/Core/TypedData/MapDataNormalizeTest.php --- b/core/tests/Drupal/Tests/Core/TypedData/MapDataNormalizeTest.php +++ b/core/tests/Drupal/Tests/Core/TypedData/MapDataNormalizeTest.php @@ -34,7 +34,6 @@ parent::setUp(); $this->serializer = \Drupal::service('serializer'); $this->typedDataManager = \Drupal::typedDataManager(); - } /**