Version 1
[yaffs-website] / web / core / modules / system / tests / modules / test_page_test / src / Form / TestForm.php
1 <?php
2
3 namespace Drupal\test_page_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Defines a test form for testing assertions.
10  */
11 class TestForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function buildForm(array $form, FormStateInterface $form_state) {
17     $form['test_table'] = [
18       '#type' => 'table',
19       '#header' => ['Column 1', 'Column 2', 'Column 3'],
20       'row_1' => [
21         'col_1' => ['#plain_text' => 'foo'],
22         'col_2' => ['#plain_text' => 'bar'],
23         'col_3' => ['#plain_text' => 'baz'],
24       ],
25       'row_2' => [
26         'col_1' => ['#plain_text' => 'one'],
27         'col_2' => ['#plain_text' => 'two'],
28         'col_3' => ['#plain_text' => 'three'],
29       ],
30     ];
31
32     $form['name'] = [
33       '#type' => 'textfield',
34       '#title' => 'Name',
35       '#default_value' => 'Test name',
36     ];
37
38     $form['checkbox_enabled'] = [
39       '#type' => 'checkbox',
40       '#title' => 'Checkbox enabled',
41       '#default_value' => TRUE,
42     ];
43
44     $form['checkbox_disabled'] = [
45       '#type' => 'checkbox',
46       '#title' => 'Checkbox disabled',
47       '#default_value' => FALSE,
48     ];
49
50     $form['description'] = [
51       '#type' => 'textfield',
52       '#title' => 'Description',
53       '#default_value' => '',
54     ];
55
56     $form['options'] = [
57       '#type' => 'select',
58       '#title' => 'Options',
59       '#options' => [
60         1 => 'one',
61         2 => 'two',
62         3 => 'three',
63       ],
64       '#default_value' => 2,
65     ];
66
67     $form['save'] = [
68       '#type' => 'submit',
69       '#value' => $this->t('Save'),
70     ];
71
72     return $form;
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function getFormId() {
79     return 'test_page_form';
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public function submitForm(array &$form, FormStateInterface $form_state) {
86     // Empty on purpose, we just want to test the rendered form elements.
87   }
88
89 }