3 namespace Drupal\Core\Layout;
5 use Drupal\Component\Utility\NestedArray;
6 use Drupal\Core\Plugin\PluginBase;
9 * Provides a default class for Layout plugins.
12 * The layout system is currently experimental and should only be leveraged by
13 * experimental modules and development releases of contributed modules.
14 * See https://www.drupal.org/core/experimental for more information.
16 class LayoutDefault extends PluginBase implements LayoutInterface {
19 * The layout definition.
21 * @var \Drupal\Core\Layout\LayoutDefinition
23 protected $pluginDefinition;
28 public function __construct(array $configuration, $plugin_id, $plugin_definition) {
29 parent::__construct($configuration, $plugin_id, $plugin_definition);
30 $this->setConfiguration($configuration);
36 public function build(array $regions) {
37 // Ensure $build only contains defined regions and in the order defined.
39 foreach ($this->getPluginDefinition()->getRegionNames() as $region_name) {
40 if (array_key_exists($region_name, $regions)) {
41 $build[$region_name] = $regions[$region_name];
44 $build['#settings'] = $this->getConfiguration();
45 $build['#layout'] = $this->pluginDefinition;
46 $build['#theme'] = $this->pluginDefinition->getThemeHook();
47 if ($library = $this->pluginDefinition->getLibrary()) {
48 $build['#attached']['library'][] = $library;
56 public function getConfiguration() {
57 return $this->configuration;
63 public function setConfiguration(array $configuration) {
64 $this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration);
70 public function defaultConfiguration() {
77 public function calculateDependencies() {
84 * @return \Drupal\Core\Layout\LayoutDefinition
86 public function getPluginDefinition() {
87 return parent::getPluginDefinition();