3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * A form for testing form labels and required marks.
13 class FormTestLabelForm extends FormBase {
18 public function getFormId() {
19 return 'form_label_test_form';
25 public function buildForm(array $form, FormStateInterface $form_state) {
26 $form['form_checkboxes_test'] = [
27 '#type' => 'checkboxes',
28 '#title' => t('Checkboxes test'),
30 'first-checkbox' => t('First checkbox'),
31 'second-checkbox' => t('Second checkbox'),
32 'third-checkbox' => t('Third checkbox'),
36 $form['form_radios_test'] = [
38 '#title' => t('Radios test'),
40 'first-radio' => t('First radio'),
41 'second-radio' => t('Second radio'),
42 'third-radio' => t('Third radio'),
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>',
49 $form['form_checkbox_test'] = [
50 '#type' => 'checkbox',
51 '#title' => t('Checkbox test'),
53 $form['form_textfield_test_title_and_required'] = [
54 '#type' => 'textfield',
55 '#title' => t('Textfield test for required with title'),
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.
65 $form['form_textfield_test_title'] = [
66 '#type' => 'textfield',
67 '#title' => t('Textfield test for title only'),
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>',
73 $form['form_textfield_test_title_after'] = [
74 '#type' => 'textfield',
75 '#title' => t('Textfield test for title after element'),
76 '#title_display' => 'after',
78 $form['form_textfield_test_title_invisible'] = [
79 '#type' => 'textfield',
80 '#title' => t('Textfield test for invisible title'),
81 '#title_display' => 'invisible',
83 // Textfield test for title set not to display.
84 $form['form_textfield_test_title_no_show'] = [
85 '#type' => 'textfield',
87 // Checkboxes & radios with title as attribute.
88 $form['form_checkboxes_title_attribute'] = [
89 '#type' => 'checkboxes',
90 '#title' => 'Checkboxes test',
91 '#title_display' => 'attribute',
93 'first-checkbox' => 'First checkbox',
94 'second-checkbox' => 'Second checkbox',
98 $form['form_radios_title_attribute'] = [
100 '#title' => 'Radios test',
101 '#title_display' => 'attribute',
103 'first-radio' => 'First radio',
104 'second-radio' => 'Second radio',
108 $form['form_checkboxes_title_invisible'] = [
109 '#type' => 'checkboxes',
110 '#title' => 'Checkboxes test invisible',
111 '#title_display' => 'invisible',
113 'first-checkbox' => 'First checkbox',
114 'second-checkbox' => 'Second checkbox',
118 $form['form_radios_title_invisible'] = [
120 '#title' => 'Radios test invisible',
121 '#title_display' => 'invisible',
123 'first-radio' => 'First radio',
124 'second-radio' => 'Second radio',
134 public function submitForm(array &$form, FormStateInterface $form_state) {