Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Layout / LayoutDefinition.php
1 <?php
2
3 namespace Drupal\Core\Layout;
4
5 use Drupal\Component\Plugin\Definition\DerivablePluginDefinitionInterface;
6 use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
7 use Drupal\Component\Plugin\Definition\PluginDefinition;
8 use Drupal\Core\Plugin\Definition\DependentPluginDefinitionInterface;
9 use Drupal\Core\Plugin\Definition\DependentPluginDefinitionTrait;
10
11 /**
12  * Provides an implementation of a layout definition and its metadata.
13  */
14 class LayoutDefinition extends PluginDefinition implements PluginDefinitionInterface, DerivablePluginDefinitionInterface, DependentPluginDefinitionInterface {
15
16   use DependentPluginDefinitionTrait;
17
18   /**
19    * The name of the deriver of this layout definition, if any.
20    *
21    * @var string|null
22    */
23   protected $deriver;
24
25   /**
26    * The human-readable name.
27    *
28    * @var string
29    */
30   protected $label;
31
32   /**
33    * An optional description for advanced layouts.
34    *
35    * @var string
36    */
37   protected $description;
38
39   /**
40    * The human-readable category.
41    *
42    * @var string
43    */
44   protected $category;
45
46   /**
47    * The template file to render this layout (relative to the 'path' given).
48    *
49    * @var string|null
50    */
51   protected $template;
52
53   /**
54    * The path to the template.
55    *
56    * @var string
57    */
58   protected $templatePath;
59
60   /**
61    * The theme hook used to render this layout.
62    *
63    * @var string|null
64    */
65   protected $theme_hook;
66
67   /**
68    * Path (relative to the module or theme) to resources like icon or template.
69    *
70    * @var string
71    */
72   protected $path;
73
74   /**
75    * The asset library.
76    *
77    * @var string|null
78    */
79   protected $library;
80
81   /**
82    * The path to the preview image.
83    *
84    * @var string
85    */
86   protected $icon;
87
88   /**
89    * An associative array of regions in this layout.
90    *
91    * The key of the array is the machine name of the region, and the value is
92    * an associative array with the following keys:
93    * - label: (string) The human-readable name of the region.
94    *
95    * Any remaining keys may have special meaning for the given layout plugin,
96    * but are undefined here.
97    *
98    * @var array
99    */
100   protected $regions = [];
101
102   /**
103    * The default region.
104    *
105    * @var string
106    */
107   protected $default_region;
108
109   /**
110    * Any additional properties and values.
111    *
112    * @var array
113    */
114   protected $additional = [];
115
116   /**
117    * LayoutDefinition constructor.
118    *
119    * @param array $definition
120    *   An array of values from the annotation.
121    */
122   public function __construct(array $definition) {
123     foreach ($definition as $property => $value) {
124       $this->set($property, $value);
125     }
126   }
127
128   /**
129    * Gets any arbitrary property.
130    *
131    * @param string $property
132    *   The property to retrieve.
133    *
134    * @return mixed
135    *   The value for that property, or NULL if the property does not exist.
136    */
137   public function get($property) {
138     if (property_exists($this, $property)) {
139       $value = isset($this->{$property}) ? $this->{$property} : NULL;
140     }
141     else {
142       $value = isset($this->additional[$property]) ? $this->additional[$property] : NULL;
143     }
144     return $value;
145   }
146
147   /**
148    * Sets a value to an arbitrary property.
149    *
150    * @param string $property
151    *   The property to use for the value.
152    * @param mixed $value
153    *   The value to set.
154    *
155    * @return $this
156    */
157   public function set($property, $value) {
158     if (property_exists($this, $property)) {
159       $this->{$property} = $value;
160     }
161     else {
162       $this->additional[$property] = $value;
163     }
164     return $this;
165   }
166
167   /**
168    * Gets the human-readable name of the layout definition.
169    *
170    * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
171    *   The human-readable name of the layout definition.
172    */
173   public function getLabel() {
174     return $this->label;
175   }
176
177   /**
178    * Sets the human-readable name of the layout definition.
179    *
180    * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $label
181    *   The human-readable name of the layout definition.
182    *
183    * @return $this
184    */
185   public function setLabel($label) {
186     $this->label = $label;
187     return $this;
188   }
189
190   /**
191    * Gets the description of the layout definition.
192    *
193    * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
194    *   The description of the layout definition.
195    */
196   public function getDescription() {
197     return $this->description;
198   }
199
200   /**
201    * Sets the description of the layout definition.
202    *
203    * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $description
204    *   The description of the layout definition.
205    *
206    * @return $this
207    */
208   public function setDescription($description) {
209     $this->description = $description;
210     return $this;
211   }
212
213   /**
214    * Gets the human-readable category of the layout definition.
215    *
216    * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
217    *   The human-readable category of the layout definition.
218    */
219   public function getCategory() {
220     return $this->category;
221   }
222
223   /**
224    * Sets the human-readable category of the layout definition.
225    *
226    * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $category
227    *   The human-readable category of the layout definition.
228    *
229    * @return $this
230    */
231   public function setCategory($category) {
232     $this->category = $category;
233     return $this;
234   }
235
236   /**
237    * Gets the template name.
238    *
239    * @return string|null
240    *   The template name, if it exists.
241    */
242   public function getTemplate() {
243     return $this->template;
244   }
245
246   /**
247    * Sets the template name.
248    *
249    * @param string|null $template
250    *   The template name.
251    *
252    * @return $this
253    */
254   public function setTemplate($template) {
255     $this->template = $template;
256     return $this;
257   }
258
259   /**
260    * Gets the template path.
261    *
262    * @return string
263    *   The template path.
264    */
265   public function getTemplatePath() {
266     return $this->templatePath;
267   }
268
269   /**
270    * Sets the template path.
271    *
272    * @param string $template_path
273    *   The template path.
274    *
275    * @return $this
276    */
277   public function setTemplatePath($template_path) {
278     $this->templatePath = $template_path;
279     return $this;
280   }
281
282   /**
283    * Gets the theme hook.
284    *
285    * @return string|null
286    *   The theme hook, if it exists.
287    */
288   public function getThemeHook() {
289     return $this->theme_hook;
290   }
291
292   /**
293    * Sets the theme hook.
294    *
295    * @param string $theme_hook
296    *   The theme hook.
297    *
298    * @return $this
299    */
300   public function setThemeHook($theme_hook) {
301     $this->theme_hook = $theme_hook;
302     return $this;
303   }
304
305   /**
306    * Gets the base path for this layout definition.
307    *
308    * @return string
309    *   The base path.
310    */
311   public function getPath() {
312     return $this->path;
313   }
314
315   /**
316    * Sets the base path for this layout definition.
317    *
318    * @param string $path
319    *   The base path.
320    *
321    * @return $this
322    */
323   public function setPath($path) {
324     $this->path = $path;
325     return $this;
326   }
327
328   /**
329    * Gets the asset library for this layout definition.
330    *
331    * @return string|null
332    *   The asset library, if it exists.
333    */
334   public function getLibrary() {
335     return $this->library;
336   }
337
338   /**
339    * Sets the asset library for this layout definition.
340    *
341    * @param string|null $library
342    *   The asset library.
343    *
344    * @return $this
345    */
346   public function setLibrary($library) {
347     $this->library = $library;
348     return $this;
349   }
350
351   /**
352    * Gets the icon path for this layout definition.
353    *
354    * @return string|null
355    *   The icon path, if it exists.
356    */
357   public function getIconPath() {
358     return $this->icon;
359   }
360
361   /**
362    * Sets the icon path for this layout definition.
363    *
364    * @param string|null $icon
365    *   The icon path.
366    *
367    * @return $this
368    */
369   public function setIconPath($icon) {
370     $this->icon = $icon;
371     return $this;
372   }
373
374   /**
375    * Gets the regions for this layout definition.
376    *
377    * @return array[]
378    *   The layout regions. The keys of the array are the machine names of the
379    *   regions, and the values are an associative array with the following keys:
380    *   - label: (string) The human-readable name of the region.
381    *   Any remaining keys may have special meaning for the given layout plugin,
382    *   but are undefined here.
383    */
384   public function getRegions() {
385     return $this->regions;
386   }
387
388   /**
389    * Sets the regions for this layout definition.
390    *
391    * @param array[] $regions
392    *   An array of regions, see ::getRegions() for the format.
393    *
394    * @return $this
395    */
396   public function setRegions(array $regions) {
397     $this->regions = $regions;
398     return $this;
399   }
400
401   /**
402    * Gets the machine-readable region names.
403    *
404    * @return string[]
405    *   An array of machine-readable region names.
406    */
407   public function getRegionNames() {
408     return array_keys($this->getRegions());
409   }
410
411   /**
412    * Gets the human-readable region labels.
413    *
414    * @return string[]
415    *   An array of human-readable region labels.
416    */
417   public function getRegionLabels() {
418     $regions = $this->getRegions();
419     return array_combine(array_keys($regions), array_column($regions, 'label'));
420   }
421
422   /**
423    * Gets the default region.
424    *
425    * @return string
426    *   The machine-readable name of the default region.
427    */
428   public function getDefaultRegion() {
429     return $this->default_region;
430   }
431
432   /**
433    * Sets the default region.
434    *
435    * @param string $default_region
436    *   The machine-readable name of the default region.
437    *
438    * @return $this
439    */
440   public function setDefaultRegion($default_region) {
441     $this->default_region = $default_region;
442     return $this;
443   }
444
445   /**
446    * {@inheritdoc}
447    */
448   public function getDeriver() {
449     return $this->deriver;
450   }
451
452   /**
453    * {@inheritdoc}
454    */
455   public function setDeriver($deriver) {
456     $this->deriver = $deriver;
457     return $this;
458   }
459
460 }