LayoutBase.php in Layout Plugin (obsolete, use core's Layout Discovery) 8
File
src/Plugin/Layout/LayoutBase.php
View source
<?php
namespace Drupal\layout_plugin\Plugin\Layout;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\PluginFormInterface;
abstract class LayoutBase extends PluginBase implements LayoutInterface, ConfigurablePluginInterface, PluginFormInterface {
protected $configuration = [];
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getDescription() {
return isset($this->pluginDefinition['description']) ? $this->pluginDefinition['description'] : NULL;
}
public function getCategory() {
return $this->pluginDefinition['category'];
}
public function getRegionNames() {
return $this->pluginDefinition['region_names'];
}
public function getRegionDefinitions() {
return $this->pluginDefinition['regions'];
}
public function getBasePath() {
return isset($this->pluginDefinition['path']) ? $this->pluginDefinition['path'] : NULL;
}
public function getIconFilename() {
return isset($this->pluginDefinition['icon']) ? $this->pluginDefinition['icon'] : NULL;
}
public function getLibrary() {
return isset($this->pluginDefinition['library']) ? $this->pluginDefinition['library'] : NULL;
}
public function getThemeHook() {
return isset($this->pluginDefinition['theme']) ? $this->pluginDefinition['theme'] : NULL;
}
public function build(array $regions) {
$build = array_intersect_key($regions, $this
->getRegionDefinitions());
$build['#layout'] = $this
->getPluginDefinition();
$build['#settings'] = $this
->getConfiguration();
if ($theme = $this
->getThemeHook()) {
$build['#theme'] = $theme;
}
if ($library = $this
->getLibrary()) {
$build['#attached']['library'][] = $library;
}
return $build;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration = $form_state
->getValues();
}
public function getConfiguration() {
return array_merge($this
->defaultConfiguration(), $this->configuration);
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return isset($this->configuration['dependencies']) ? $this->configuration['dependencies'] : [];
}
}