Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / layout_plugin / src / Plugin / Layout / LayoutBase.php
1 <?php
2
3 namespace Drupal\layout_plugin\Plugin\Layout;
4
5 use Drupal\Component\Plugin\ConfigurablePluginInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Plugin\PluginBase;
8 use Drupal\Core\Plugin\PluginFormInterface;
9
10 /**
11  * Provides a base class for Layout plugins.
12  */
13 abstract class LayoutBase extends PluginBase implements LayoutInterface, ConfigurablePluginInterface, PluginFormInterface {
14
15   /**
16    * The layout configuration.
17    *
18    * @var array
19    */
20   protected $configuration = [];
21
22   /**
23    * Gets the human-readable name.
24    *
25    * @return \Drupal\Core\Annotation\Translation|NULL
26    *   The human-readable name.
27    */
28   public function getLabel() {
29     return $this->pluginDefinition['label'];
30   }
31
32   /**
33    * Gets the optional description for advanced layouts.
34    *
35    * @return \Drupal\Core\Annotation\Translation|NULL
36    *   The layout description.
37    */
38   public function getDescription() {
39     return isset($this->pluginDefinition['description']) ? $this->pluginDefinition['description'] : NULL;
40   }
41
42   /**
43    * Gets the human-readable category.
44    *
45    * @return \Drupal\Core\Annotation\Translation
46    *   The human-readable category.
47    */
48   public function getCategory() {
49     return $this->pluginDefinition['category'];
50   }
51
52   /**
53    * Gets human-readable list of regions keyed by machine name.
54    *
55    * @return \Drupal\Core\Annotation\Translation[]
56    *   An array of human-readable region names keyed by machine name.
57    */
58   public function getRegionNames() {
59     return $this->pluginDefinition['region_names'];
60   }
61
62   /**
63    * Gets information on regions keyed by machine name.
64    *
65    * @return array
66    *   An array of information on regions keyed by machine name.
67    */
68   public function getRegionDefinitions() {
69     return $this->pluginDefinition['regions'];
70   }
71
72   /**
73    * Gets the path to resources like icon or template.
74    *
75    * @return string|NULL
76    *   The path relative to the Drupal root.
77    */
78   public function getBasePath() {
79     return isset($this->pluginDefinition['path']) ? $this->pluginDefinition['path'] : NULL;
80   }
81
82   /**
83    * Gets the path to the preview image.
84    *
85    * This can optionally be used in the user interface to show the layout of
86    * regions visually.
87    *
88    * @return string|NULL
89    *   The path to preview image file.
90    */
91   public function getIconFilename() {
92     return isset($this->pluginDefinition['icon']) ? $this->pluginDefinition['icon'] : NULL;
93   }
94
95   /**
96    * Get the asset library.
97    *
98    * @return string|NULL
99    *   The asset library.
100    */
101   public function getLibrary() {
102     return isset($this->pluginDefinition['library']) ? $this->pluginDefinition['library'] : NULL;
103   }
104
105   /**
106    * Gets the theme hook used to render this layout.
107    *
108    * @return string|NULL
109    *   Theme hook.
110    */
111   public function getThemeHook() {
112     return isset($this->pluginDefinition['theme']) ? $this->pluginDefinition['theme'] : NULL;
113   }
114
115   /**
116    * {@inheritdoc}
117    */
118   public function build(array $regions) {
119     $build = array_intersect_key($regions, $this->getRegionDefinitions());
120     $build['#layout'] = $this->getPluginDefinition();
121     $build['#settings'] = $this->getConfiguration();
122     if ($theme = $this->getThemeHook()) {
123       $build['#theme'] = $theme;
124     }
125     if ($library = $this->getLibrary()) {
126       $build['#attached']['library'][] = $library;
127     }
128     return $build;
129   }
130
131   /**
132    * {@inheritdoc}
133    */
134   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
135     return $form;
136   }
137
138   /**
139    * {@inheritdoc}
140    */
141   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
142   }
143
144   /**
145    * {@inheritdoc}
146    */
147   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
148     $this->configuration = $form_state->getValues();
149   }
150
151   /**
152    * {@inheritdoc}
153    */
154   public function getConfiguration() {
155     return array_merge($this->defaultConfiguration(), $this->configuration);
156   }
157
158   /**
159    * {@inheritdoc}
160    */
161   public function setConfiguration(array $configuration) {
162     $this->configuration = $configuration;
163   }
164
165   /**
166    * {@inheritdoc}
167    */
168   public function defaultConfiguration() {
169     return [];
170   }
171
172   /**
173    * {@inheritdoc}
174    */
175   public function calculateDependencies() {
176     return isset($this->configuration['dependencies']) ? $this->configuration['dependencies'] : [];
177   }
178
179 }