Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / tests / modules / views_test_data / src / Plugin / views / display_extender / DisplayExtenderTest.php
1 <?php
2
3 namespace Drupal\views_test_data\Plugin\views\display_extender;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
7
8 /**
9  * Defines a display extender test plugin.
10  *
11  * @ViewsDisplayExtender(
12  *   id = "display_extender_test",
13  *   title = @Translation("Display extender test")
14  * )
15  */
16 class DisplayExtenderTest extends DisplayExtenderPluginBase {
17
18   /**
19    * Stores some state booleans to be sure a certain method got called.
20    *
21    * @var array
22    */
23   public $testState;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function defineOptions() {
29     $options = parent::defineOptions();
30
31     $options['test_extender_test_option'] = ['default' => $this->t('Empty')];
32
33     return $options;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function optionsSummary(&$categories, &$options) {
40     parent::optionsSummary($categories, $options);
41
42     $categories['display_extender_test'] = [
43       'title' => $this->t('Display extender test settings'),
44       'column' => 'second',
45       'build' => [
46         '#weight' => -100,
47       ],
48     ];
49
50     $options['test_extender_test_option'] = [
51       'category' => 'display_extender_test',
52       'title' => $this->t('Test option'),
53       'value' => views_ui_truncate($this->options['test_extender_test_option'], 24),
54     ];
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
61     switch ($form_state->get('section')) {
62       case 'test_extender_test_option':
63         $form['#title'] .= $this->t('Test option');
64         $form['test_extender_test_option'] = [
65           '#title' => $this->t('Test option'),
66           '#type' => 'textfield',
67           '#description' => $this->t('This is a textfield for test_option.'),
68           '#default_value' => $this->options['test_extender_test_option'],
69         ];
70     }
71   }
72
73   /**
74    * {@inheritdoc}
75    */
76   public function submitOptionsForm(&$form, FormStateInterface $form_state) {
77     parent::submitOptionsForm($form, $form_state);
78     switch ($form_state->get('section')) {
79       case 'test_extender_test_option':
80         $this->options['test_extender_test_option'] = $form_state->getValue('test_extender_test_option');
81         break;
82     }
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function defaultableSections(&$sections, $section = NULL) {
89     $sections['test_extender_test_option'] = ['test_extender_test_option'];
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function query() {
96     $this->testState['query'] = TRUE;
97   }
98
99   /**
100    * {@inheritdoc}
101    */
102   public function preExecute() {
103     $this->testState['preExecute'] = TRUE;
104   }
105
106 }