SusyLayout.php

Public

Get raw version
php
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  * Contains \Drupal\my_layouts\Plugin\Layout\SusyLayout.
  6.  */
  7.  
  8. namespace Drupal\my_layouts\Plugin\Layout;
  9.  
  10. use Drupal\Core\Form\FormStateInterface;
  11. use Drupal\layout_plugin\Plugin\Layout\LayoutBase;
  12.  
  13. /**
  14.  * The plugin that handles the default layout template.
  15.  *
  16.  * @ingroup layout_template_plugins
  17.  *
  18.  * @Layout(
  19.  * id = "susy",
  20.  * label = @Translation("Susy layout (with settings)"),
  21.  * category = @Translation("Susy"),
  22.  * description = @Translation("Susy sample description"),
  23.  * type = "page",
  24.  * help = @Translation("Layout"),
  25.  * template = "templates/susy/susy",
  26.  * icon = "templates/susy/susy.png",
  27.  * regions = {
  28.  * "top" = {
  29.  * "label" = @Translation("Top Region"),
  30.  * "plugin_id" = "default"
  31.  * },
  32.  * "left" = {
  33.  * "label" = @Translation("Left Region"),
  34.  * "plugin_id" = "default"
  35.  * },
  36.  * "middle" = {
  37.  * "label" = @Translation("Middle Region"),
  38.  * "plugin_id" = "default"
  39.  * },
  40.  * "right" = {
  41.  * "label" = @Translation("Right Region"),
  42.  * "plugin_id" = "default"
  43.  * },
  44.  * "bottom" = {
  45.  * "label" = @Translation("Bottom Region"),
  46.  * "plugin_id" = "default"
  47.  * }
  48.  * }
  49.  * )
  50.  */
  51.  
  52. // Next, try using derivatives, see
  53. // https://www.drupal.org/node/2578731#using-derivatives
  54.  
  55. class SusyLayout extends LayoutBase {
  56.  
  57. /**
  58.   * {@inheritdoc}
  59.   */
  60. public function defaultConfiguration() {
  61. return [
  62. 'css_id' => '',
  63. 'css_classes' => '',
  64. 'susy_columns_left' => '',
  65. 'susy_columns_middle' => '',
  66. 'susy_columns_right' => '',
  67. ];
  68. }
  69.  
  70. /**
  71.   * {@inheritdoc}
  72.   */
  73. public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  74. $configuration = $this->getConfiguration();
  75.  
  76. $form['css_classes'] = [
  77. '#type' => 'textfield',
  78. '#title' => t('Classes'),
  79. '#description' => 'Add classes to the outer wrapper element.',
  80. '#weight' => 1,
  81. ];
  82.  
  83. $form['css_id'] = [
  84. '#type' => 'textfield',
  85. '#title' => t('Id'),
  86. '#description' => 'Add an id to the outer wrapper element.',
  87. '#default_value' => $configuration['css_id'],
  88. '#weight' => 2,
  89. ];
  90.  
  91. $form['susy_columns_left'] = [
  92. '#type' => 'textfield',
  93. '#title' => t('Susy Columns Left'),
  94. '#description' => 'Define your Susy columns in the Left Region.',
  95. '#default_value' => $configuration['susy_columns_left'],
  96. '#weight' => 3,
  97. ];
  98.  
  99. $form['susy_columns_middle'] = [
  100. '#type' => 'textfield',
  101. '#title' => t('Susy Columns Middle'),
  102. '#description' => 'Define your Susy columns in the Middle Region.',
  103. '#default_value' => $configuration['susy_columns_middle'],
  104. '#weight' => 4,
  105. ];
  106.  
  107. $form['susy_columns_right'] = [
  108. '#type' => 'textfield',
  109. '#title' => t('Susy Columns Right'),
  110. '#description' => 'Define your Susy columns in the Right Region.',
  111. '#default_value' => $configuration['susy_columns_right'],
  112. '#weight' => 5,
  113. ];
  114.  
  115. return $form;
  116. }
  117.  
  118. /**
  119.   * {@inheritdoc}
  120.   */
  121. public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  122. $defaults = $this->defaultConfiguration();
  123. $this->configuration['css_classes'] = $form_state->getValue('css_classes', $defaults['css_classes']);
  124. $this->configuration['css_id'] = $form_state->getValue('css_id', $defaults['css_id']);
  125. $this->configuration['susy_columns_left'] = $form_state->getValue('susy_columns_left', $defaults['susy_columns_left']);
  126. $this->configuration['susy_columns_middle'] = $form_state->getValue('susy_columns_middle', $defaults['susy_columns_middle']);
  127. $this->configuration['susy_columns_right'] = $form_state->getValue('susy_columns_right', $defaults['susy_columns_right']);
  128. }
  129.  
  130. }