Problem/Motivation
Problem/Motivation
\Drupal\Core\TypedData\Plugin\DataType\Map
allows a TypedData object to be created that emulates an associative array. Unlike all other TypedData objects, a value of the Map
type does not require its properties to have definitions. It's "freeform" so to speak.
It seems that the original intent was to have it serve primarily as a base class for other complex data, but not be the primary data itself. However, that usecase was not precluded.
Several implementations in Drupal core and contrib have defined values that use the raw Map
type.
The serialization system has default normalizers for objects that implement ComplexDataInterface
, which the Map
class does. It makes a call to getProperties()
, then normalizes each of those properties.
Every TypedData value instance is supposed to carry a definition. The default implementation of getProperties
uses this definition and the static method getPropertyDefinitions
on it to return definitions for each property of the map.
Unfortunately, raw uses of Map and MapItem don't need to have those definitions statically defined. So an empty list of definitions is returned and the serializer thinks: "great, there's nothing to do!"
The serializers must then be able to take this into account. A TypedData object which returns no properties should simply escape the TypedData system and be normalized as a PHP value.
Remaining tasks
1. Write a failing test
2. Auto cast Map data values into its properties
3. Decide if a REST test is necessary, and how to test it with Core only, see #60
Use Core's link options(Map dataType) serialization test instead
4. The newest patch has been tested on 8.4.x,So it can be directly used on 8.4.
Back port the patch to 8.4.x (Given the timing, this backport won't get committed, but it's still valuable when people search for a solution on 8.4.x for the next 6 months or so.)
User interface changes
None
API changes
None
Data model changes
None