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