comparison core/lib/Drupal/Core/Layout/LayoutDefault.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Core\Layout;
4
5 use Drupal\Component\Utility\NestedArray;
6 use Drupal\Core\Plugin\PluginBase;
7
8 /**
9 * Provides a default class for Layout plugins.
10 */
11 class LayoutDefault extends PluginBase implements LayoutInterface {
12
13 /**
14 * The layout definition.
15 *
16 * @var \Drupal\Core\Layout\LayoutDefinition
17 */
18 protected $pluginDefinition;
19
20 /**
21 * {@inheritdoc}
22 */
23 public function __construct(array $configuration, $plugin_id, $plugin_definition) {
24 parent::__construct($configuration, $plugin_id, $plugin_definition);
25 $this->setConfiguration($configuration);
26 }
27
28 /**
29 * {@inheritdoc}
30 */
31 public function build(array $regions) {
32 // Ensure $build only contains defined regions and in the order defined.
33 $build = [];
34 foreach ($this->getPluginDefinition()->getRegionNames() as $region_name) {
35 if (array_key_exists($region_name, $regions)) {
36 $build[$region_name] = $regions[$region_name];
37 }
38 }
39 $build['#settings'] = $this->getConfiguration();
40 $build['#layout'] = $this->pluginDefinition;
41 $build['#theme'] = $this->pluginDefinition->getThemeHook();
42 if ($library = $this->pluginDefinition->getLibrary()) {
43 $build['#attached']['library'][] = $library;
44 }
45 return $build;
46 }
47
48 /**
49 * {@inheritdoc}
50 */
51 public function getConfiguration() {
52 return $this->configuration;
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function setConfiguration(array $configuration) {
59 $this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration);
60 }
61
62 /**
63 * {@inheritdoc}
64 */
65 public function defaultConfiguration() {
66 return [];
67 }
68
69 /**
70 * {@inheritdoc}
71 */
72 public function calculateDependencies() {
73 return [];
74 }
75
76 /**
77 * {@inheritdoc}
78 *
79 * @return \Drupal\Core\Layout\LayoutDefinition
80 */
81 public function getPluginDefinition() {
82 return parent::getPluginDefinition();
83 }
84
85 }