Version 1
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestLabelForm.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * A form for testing form labels and required marks.
10  */
11 class FormTestLabelForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'form_label_test_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state) {
24     $form['form_checkboxes_test'] = [
25       '#type' => 'checkboxes',
26       '#title' => t('Checkboxes test'),
27       '#options' => [
28         'first-checkbox' => t('First checkbox'),
29         'second-checkbox' => t('Second checkbox'),
30         'third-checkbox' => t('Third checkbox'),
31         '0' => t('0'),
32       ],
33     ];
34     $form['form_radios_test'] = [
35       '#type' => 'radios',
36       '#title' => t('Radios test'),
37       '#options' => [
38         'first-radio' => t('First radio'),
39         'second-radio' => t('Second radio'),
40         'third-radio' => t('Third radio'),
41         '0' => t('0'),
42       ],
43       // Test #field_prefix and #field_suffix placement.
44       '#field_prefix' => '<span id="form-test-radios-field-prefix">' . t('Radios #field_prefix element') . '</span>',
45       '#field_suffix' => '<span id="form-test-radios-field-suffix">' . t('Radios #field_suffix element') . '</span>',
46     ];
47     $form['form_checkbox_test'] = [
48       '#type' => 'checkbox',
49       '#title' => t('Checkbox test'),
50     ];
51     $form['form_textfield_test_title_and_required'] = [
52       '#type' => 'textfield',
53       '#title' => t('Textfield test for required with title'),
54       '#required' => TRUE,
55     ];
56     $form['form_textfield_test_no_title_required'] = [
57       '#type' => 'textfield',
58       // We use an empty title, since not setting #title suppresses the label
59       // and required marker.
60       '#title' => '',
61       '#required' => TRUE,
62     ];
63     $form['form_textfield_test_title'] = [
64       '#type' => 'textfield',
65       '#title' => t('Textfield test for title only'),
66       // Not required.
67       // Test #prefix and #suffix placement.
68       '#prefix' => '<div id="form-test-textfield-title-prefix">' . t('Textfield #prefix element') . '</div>',
69       '#suffix' => '<div id="form-test-textfield-title-suffix">' . t('Textfield #suffix element') . '</div>',
70     ];
71     $form['form_textfield_test_title_after'] = [
72       '#type' => 'textfield',
73       '#title' => t('Textfield test for title after element'),
74       '#title_display' => 'after',
75     ];
76     $form['form_textfield_test_title_invisible'] = [
77       '#type' => 'textfield',
78       '#title' => t('Textfield test for invisible title'),
79       '#title_display' => 'invisible',
80     ];
81     // Textfield test for title set not to display.
82     $form['form_textfield_test_title_no_show'] = [
83       '#type' => 'textfield',
84     ];
85     // Checkboxes & radios with title as attribute.
86     $form['form_checkboxes_title_attribute'] = [
87       '#type' => 'checkboxes',
88       '#title' => 'Checkboxes test',
89       '#title_display' => 'attribute',
90       '#options' => [
91         'first-checkbox' => 'First checkbox',
92         'second-checkbox' => 'Second checkbox',
93       ],
94       '#required' => TRUE,
95     ];
96     $form['form_radios_title_attribute'] = [
97       '#type' => 'radios',
98       '#title' => 'Radios test',
99       '#title_display' => 'attribute',
100       '#options' => [
101         'first-radio' => 'First radio',
102         'second-radio' => 'Second radio',
103       ],
104       '#required' => TRUE,
105     ];
106     $form['form_checkboxes_title_invisible'] = [
107       '#type' => 'checkboxes',
108       '#title' => 'Checkboxes test invisible',
109       '#title_display' => 'invisible',
110       '#options' => [
111         'first-checkbox' => 'First checkbox',
112         'second-checkbox' => 'Second checkbox',
113       ],
114       '#required' => TRUE,
115     ];
116     $form['form_radios_title_invisible'] = [
117       '#type' => 'radios',
118       '#title' => 'Radios test invisible',
119       '#title_display' => 'invisible',
120       '#options' => [
121         'first-radio' => 'First radio',
122         'second-radio' => 'Second radio',
123       ],
124       '#required' => TRUE,
125     ];
126     return $form;
127   }
128
129   /**
130    * {@inheritdoc}
131    */
132   public function submitForm(array &$form, FormStateInterface $form_state) {
133   }
134
135 }