6753be4c3e723296e1967df524a9854696f5ebf2
[yaffs-website] / Plugin / Layout / LayoutExampleTest.php
1 <?php
2
3 namespace Drupal\layout_plugin_example\Plugin\Layout;
4 use Drupal\Core\Form\FormStateInterface;
5 use Drupal\layout_plugin\Plugin\Layout\LayoutBase;
6
7 /**
8  * The plugin that handles the default layout template.
9  *
10  * @ingroup layout_template_plugins
11  *
12  * @Layout(
13  *   id = "layout_example_test",
14  *   label = @Translation("Test layout (with settings)"),
15  *   category = @Translation("Examples"),
16  *   description = @Translation("Test1 sample description"),
17  *   type = "page",
18  *   help = @Translation("Layout"),
19  *   template = "templates/layout-example-test",
20  *   regions = {
21  *     "top" = {
22  *       "label" = @Translation("Top Region"),
23  *       "plugin_id" = "default"
24  *     },
25  *    "bottom" = {
26  *       "label" = @Translation("Bottom Region"),
27  *       "plugin_id" = "default"
28  *     }
29  *   }
30  * )
31  */
32 class LayoutExampleTest extends LayoutBase {
33
34   /**
35    * {@inheritdoc}
36    */
37   public function defaultConfiguration() {
38     return parent::defaultConfiguration() + [
39       'setting_1' => 'Default',
40     ];
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
47     $configuration = $this->getConfiguration();
48     $form['setting_1'] = [
49       '#type' => 'textfield',
50       '#title' => 'Blah',
51       '#default_value' => $configuration['setting_1'],
52     ];
53     return $form;
54   }
55
56   /**
57    * @inheritDoc
58    */
59   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
60     parent::submitConfigurationForm($form, $form_state);
61
62     $this->configuration['setting_1'] = $form_state->getValue('setting_1');
63   }
64
65 }