3 namespace Drupal\Core\TypedData;
6 * A typed data definition class for defining maps.
8 class MapDataDefinition extends ComplexDataDefinitionBase {
11 * The name of the main property, or NULL if there is none.
15 protected $mainPropertyName = NULL;
18 * Creates a new map definition.
21 * (optional) The data type of the map. Defaults to 'map'.
25 public static function create($type = 'map') {
26 $definition['type'] = $type;
27 return new static($definition);
33 public static function createFromDataType($data_type) {
34 return static::create($data_type);
40 public function getPropertyDefinitions() {
41 if (!isset($this->propertyDefinitions)) {
42 $this->propertyDefinitions = [];
44 return $this->propertyDefinitions;
48 * Sets the definition of a map property.
51 * The name of the property to define.
52 * @param \Drupal\Core\TypedData\DataDefinitionInterface|null $definition
53 * (optional) The property definition to set, or NULL to unset it.
57 public function setPropertyDefinition($name, DataDefinitionInterface $definition = NULL) {
58 if (isset($definition)) {
59 $this->propertyDefinitions[$name] = $definition;
62 unset($this->propertyDefinitions[$name]);
70 public function getMainPropertyName() {
71 return $this->mainPropertyName;
75 * Sets the main property name.
77 * @param string|null $name
78 * The name of the main property, or NULL if there is none.
82 public function setMainPropertyName($name) {
83 $this->mainPropertyName = $name;