-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPatternLibraryPluginDefinition.php
More file actions
187 lines (166 loc) · 4.13 KB
/
PatternLibraryPluginDefinition.php
File metadata and controls
187 lines (166 loc) · 4.13 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
namespace Drupal\patternkit;
use Drupal\Component\Plugin\Definition\DerivablePluginDefinitionInterface;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Core\Plugin\Definition\DependentPluginDefinitionInterface;
use Drupal\Core\Plugin\Definition\DependentPluginDefinitionTrait;
/**
* Provides an implementation of a definition and its metadata.
*/
class PatternLibraryPluginDefinition extends PluginDefinition implements DerivablePluginDefinitionInterface, DependentPluginDefinitionInterface {
use DependentPluginDefinitionTrait;
/**
* The name of the deriver of this definition, if any.
*
* @var string|null
*/
protected $deriver;
/**
* The human-readable name.
*
* @var string
*/
protected $label;
/**
* An optional description.
*
* @var string
*/
protected $description;
/**
* The human-readable category.
*
* @var string
*/
protected $category;
/**
* Any additional properties and values.
*
* @var array
*/
protected $additional = [];
/**
* Constructor.
*
* @param array $definition
* Provide an array of values from the annotation.
*/
public function __construct(array $definition) {
foreach ($definition as $property => $value) {
$this->set($property, $value);
}
}
/**
* Gets any arbitrary property.
*
* @param string $property
* The property to retrieve.
*
* @return mixed
* The value for that property, or NULL if the property does not exist.
*/
public function get($property) {
if (property_exists($this, $property)) {
$value = isset($this->{$property}) ? $this->{$property} : NULL;
}
else {
$value = isset($this->additional[$property]) ? $this->additional[$property] : NULL;
}
return $value;
}
/**
* Sets a value to an arbitrary property.
*
* @param string $property
* The property to use for the value.
* @param mixed $value
* The value to set.
*
* @return $this
*/
public function set($property, $value) {
if (property_exists($this, $property)) {
$this->{$property} = $value;
}
else {
$this->additional[$property] = $value;
}
return $this;
}
/**
* Gets the human-readable name of the definition.
*
* @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
* The human-readable name of the definition.
*/
public function getLabel() {
return $this->label;
}
/**
* Sets the human-readable name of the definition.
*
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $label
* The human-readable name of the definition.
*
* @return $this
*/
public function setLabel($label) {
$this->label = $label;
return $this;
}
/**
* Gets the description of the definition.
*
* @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
* The description of the definition.
*/
public function getDescription() {
return $this->description;
}
/**
* Sets the description of the definition.
*
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $description
* The description of the definition.
*
* @return $this
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}
/**
* Gets the human-readable category of the definition.
*
* @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
* The human-readable category of the definition.
*/
public function getCategory() {
return $this->category ?? t('default');
}
/**
* Sets the human-readable category of the definition.
*
* @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $category
* The human-readable category of the definition.
*
* @return $this
*/
public function setCategory($category) {
$this->category = $category ?? t('default');
return $this;
}
/**
* {@inheritdoc}
*/
public function getDeriver() {
return $this->deriver;
}
/**
* {@inheritdoc}
*/
public function setDeriver($deriver) {
$this->deriver = $deriver;
return $this;
}
}