61b975a471825d53af63e6804d6696bf578f905b
[yaffs-website] / web / core / modules / layout_builder / src / SectionStorage / SectionStorageDefinition.php
1 <?php
2
3 namespace Drupal\layout_builder\SectionStorage;
4
5 use Drupal\Component\Plugin\Definition\PluginDefinition;
6
7 /**
8  * Provides section storage type plugin definition.
9  *
10  * @internal
11  *   Layout Builder is currently experimental and should only be leveraged by
12  *   experimental modules and development releases of contributed modules.
13  *   See https://www.drupal.org/core/experimental for more information.
14  */
15 class SectionStorageDefinition extends PluginDefinition {
16
17   /**
18    * Any additional properties and values.
19    *
20    * @var array
21    */
22   protected $additional = [];
23
24   /**
25    * LayoutDefinition constructor.
26    *
27    * @param array $definition
28    *   An array of values from the annotation.
29    */
30   public function __construct(array $definition = []) {
31     foreach ($definition as $property => $value) {
32       $this->set($property, $value);
33     }
34   }
35
36   /**
37    * Gets any arbitrary property.
38    *
39    * @param string $property
40    *   The property to retrieve.
41    *
42    * @return mixed
43    *   The value for that property, or NULL if the property does not exist.
44    */
45   public function get($property) {
46     if (property_exists($this, $property)) {
47       $value = isset($this->{$property}) ? $this->{$property} : NULL;
48     }
49     else {
50       $value = isset($this->additional[$property]) ? $this->additional[$property] : NULL;
51     }
52     return $value;
53   }
54
55   /**
56    * Sets a value to an arbitrary property.
57    *
58    * @param string $property
59    *   The property to use for the value.
60    * @param mixed $value
61    *   The value to set.
62    *
63    * @return $this
64    */
65   public function set($property, $value) {
66     if (property_exists($this, $property)) {
67       $this->{$property} = $value;
68     }
69     else {
70       $this->additional[$property] = $value;
71     }
72     return $this;
73   }
74
75 }