123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace Drupal\Core\Layout;
- use Drupal\Component\Utility\NestedArray;
- use Drupal\Core\Form\FormStateInterface;
- use Drupal\Core\Plugin\PluginBase;
- use Drupal\Core\Plugin\PluginFormInterface;
- /**
- * Provides a default class for Layout plugins.
- */
- class LayoutDefault extends PluginBase implements LayoutInterface, PluginFormInterface {
- /**
- * The layout definition.
- *
- * @var \Drupal\Core\Layout\LayoutDefinition
- */
- protected $pluginDefinition;
- /**
- * {@inheritdoc}
- */
- public function __construct(array $configuration, $plugin_id, $plugin_definition) {
- parent::__construct($configuration, $plugin_id, $plugin_definition);
- $this->setConfiguration($configuration);
- }
- /**
- * {@inheritdoc}
- */
- public function build(array $regions) {
- // Ensure $build only contains defined regions and in the order defined.
- $build = [];
- foreach ($this->getPluginDefinition()->getRegionNames() as $region_name) {
- if (array_key_exists($region_name, $regions)) {
- $build[$region_name] = $regions[$region_name];
- }
- }
- $build['#settings'] = $this->getConfiguration();
- $build['#layout'] = $this->pluginDefinition;
- $build['#theme'] = $this->pluginDefinition->getThemeHook();
- if ($library = $this->pluginDefinition->getLibrary()) {
- $build['#attached']['library'][] = $library;
- }
- return $build;
- }
- /**
- * {@inheritdoc}
- */
- public function getConfiguration() {
- return $this->configuration;
- }
- /**
- * {@inheritdoc}
- */
- public function setConfiguration(array $configuration) {
- $this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration);
- }
- /**
- * {@inheritdoc}
- */
- public function defaultConfiguration() {
- return [
- 'label' => '',
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function calculateDependencies() {
- return [];
- }
- /**
- * {@inheritdoc}
- *
- * @return \Drupal\Core\Layout\LayoutDefinition
- */
- public function getPluginDefinition() {
- return parent::getPluginDefinition();
- }
- /**
- * {@inheritdoc}
- */
- public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
- $form['label'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Administrative label'),
- '#default_value' => $this->configuration['label'],
- ];
- return $form;
- }
- /**
- * {@inheritdoc}
- */
- public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
- }
- /**
- * {@inheritdoc}
- */
- public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
- $this->configuration['label'] = $form_state->getValue('label');
- }
- }
|