Version 1
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / MapDataDefinition.php
1 <?php
2
3 namespace Drupal\Core\TypedData;
4
5 /**
6  * A typed data definition class for defining maps.
7  */
8 class MapDataDefinition extends ComplexDataDefinitionBase {
9
10   /**
11    * The name of the main property, or NULL if there is none.
12    *
13    * @var string
14    */
15   protected $mainPropertyName = NULL;
16
17   /**
18    * Creates a new map definition.
19    *
20    * @param string $type
21    *   (optional) The data type of the map. Defaults to 'map'.
22    *
23    * @return static
24    */
25   public static function create($type = 'map') {
26     $definition['type'] = $type;
27     return new static($definition);
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public static function createFromDataType($data_type) {
34     return static::create($data_type);
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function getPropertyDefinitions() {
41     if (!isset($this->propertyDefinitions)) {
42       $this->propertyDefinitions = [];
43     }
44     return $this->propertyDefinitions;
45   }
46
47   /**
48    * Sets the definition of a map property.
49    *
50    * @param string $name
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.
54    *
55    * @return $this
56    */
57   public function setPropertyDefinition($name, DataDefinitionInterface $definition = NULL) {
58     if (isset($definition)) {
59       $this->propertyDefinitions[$name] = $definition;
60     }
61     else {
62       unset($this->propertyDefinitions[$name]);
63     }
64     return $this;
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function getMainPropertyName() {
71     return $this->mainPropertyName;
72   }
73
74   /**
75    * Sets the main property name.
76    *
77    * @param string|null $name
78    *   The name of the main property, or NULL if there is none.
79    *
80    * @return $this
81    */
82   public function setMainPropertyName($name) {
83     $this->mainPropertyName = $name;
84     return $this;
85   }
86
87 }