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,29 +157,22 @@ */ 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 - elseif (get_class($this->getDataDefinition()) == 'Drupal\Core\TypedData\MapDataDefinition') { - $values = $this->values; + $property_definitions = $this->definition->getPropertyDefinitions(); + if (empty($property_definitions) && get_class($this->getDataDefinition()) == 'Drupal\Core\TypedData\MapDataDefinition') { + $values = $this->getValue(); if (is_array($values)) { foreach ($values as $key => $value) { if (!empty($value) && is_array($value)) { - $properties[$key] = \Drupal::typedDataManager()->create( + $data = \Drupal::typedDataManager()->create( MapDataDefinition::create(), $value, $key ); } else { - $properties[$key] = \Drupal::typedDataManager()->create( + $data = \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 @@ -188,7 +181,13 @@ $key ); } - }; + $this->definition->setPropertyDefinition($key, $data->getDataDefinition()); + } + } + } + foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { + if ($include_computed || !$definition->isComputed()) { + $properties[$name] = $this->get($name); } }