summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/TypedData/MapDataDefinition.php
blob: 203e4a367edd1d2df51417aea7619ece317ec93f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

namespace Drupal\Core\TypedData;

/**
 * A typed data definition class for defining maps.
 */
class MapDataDefinition extends ComplexDataDefinitionBase {

  /**
   * The name of the main property, or NULL if there is none.
   *
   * @var string
   */
  protected $mainPropertyName = NULL;

  /**
   * Creates a new map definition.
   *
   * @param string $type
   *   (optional) The data type of the map. Defaults to 'map'.
   *
   * @return static
   */
  public static function create($type = 'map') {
    $definition['type'] = $type;
    return new static($definition);
  }

  /**
   * {@inheritdoc}
   */
  public static function createFromDataType($data_type) {
    return static::create($data_type);
  }

  /**
   * {@inheritdoc}
   */
  public function getPropertyDefinitions() {
    if (!isset($this->propertyDefinitions)) {
      $this->propertyDefinitions = [];
    }
    return $this->propertyDefinitions;
  }

  /**
   * Sets the definition of a map property.
   *
   * @param string $name
   *   The name of the property to define.
   * @param \Drupal\Core\TypedData\DataDefinitionInterface|null $definition
   *   (optional) The property definition to set, or NULL to unset it.
   *
   * @return $this
   */
  public function setPropertyDefinition($name, DataDefinitionInterface $definition = NULL) {
    if (isset($definition)) {
      $this->propertyDefinitions[$name] = $definition;
    }
    else {
      unset($this->propertyDefinitions[$name]);
    }
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getMainPropertyName() {
    return $this->mainPropertyName;
  }

  /**
   * Sets the main property name.
   *
   * @param string|null $name
   *   The name of the main property, or NULL if there is none.
   *
   * @return $this
   */
  public function setMainPropertyName($name) {
    $this->mainPropertyName = $name;
    return $this;
  }

}