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 @@ -65,8 +65,6 @@ /** * Builds some example type data object with no properties. - * - * @return \Drupal\Core\TypedData\TypedDataInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function buildExampleTypedData() { $tree = [ @@ -84,8 +82,6 @@ /** * Builds some example type data object with properties. - * - * @return \Drupal\Core\TypedData\TypedDataInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function buildExampleTypedDataWithProperties() { $tree = [ only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php @@ -2,6 +2,7 @@ namespace Drupal\Core\TypedData\Plugin\DataType; +use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\TypedData; use Drupal\Core\TypedData\ComplexDataInterface; @@ -113,7 +114,8 @@ public function get($property_name) { $value = $this->values[$property_name]; } // If the property is unknown, this will throw an exception. - $this->properties[$property_name] = $this->getTypedDataManager()->getPropertyInstance($this, $property_name, $value); + $this->properties[$property_name] = $this->getTypedDataManager() + ->getPropertyInstance($this, $property_name, $value); } return $this->properties[$property_name]; } @@ -155,11 +157,29 @@ protected function writePropertyValue($property_name, $value) { */ public function getProperties($include_computed = FALSE) { $properties = []; - foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { - if ($include_computed || !$definition->isComputed()) { - $properties[$name] = $this->get($name); + $PropertyDefinitions = $this->definition->getPropertyDefinitions(); + if (!empty($PropertyDefinitions)) { + foreach ($PropertyDefinitions 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 setPropertyDefinition, + //Auto creating the PropertyDefinition so that it can be normalized + elseif (get_class($this->getDataDefinition()) == 'Drupal\Core\TypedData\MapDataDefinition') { + $values = $this->values; + if (is_array($values)) { + foreach ($values as $key => $value) { + $properties[$key] = \Drupal::typedDataManager()->create( + DataDefinition::create('any'), + $value, + $key + ); + }; } } + return $properties; }