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.
11 class FormTestLabelForm extends FormBase {
16 public function getFormId() {
17 return 'form_label_test_form';
23 public function buildForm(array $form, FormStateInterface $form_state) {
24 $form['form_checkboxes_test'] = [
25 '#type' => 'checkboxes',
26 '#title' => t('Checkboxes test'),
28 'first-checkbox' => t('First checkbox'),
29 'second-checkbox' => t('Second checkbox'),
30 'third-checkbox' => t('Third checkbox'),
34 $form['form_radios_test'] = [
36 '#title' => t('Radios test'),
38 'first-radio' => t('First radio'),
39 'second-radio' => t('Second radio'),
40 'third-radio' => t('Third radio'),
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>',
47 $form['form_checkbox_test'] = [
48 '#type' => 'checkbox',
49 '#title' => t('Checkbox test'),
51 $form['form_textfield_test_title_and_required'] = [
52 '#type' => 'textfield',
53 '#title' => t('Textfield test for required with title'),
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.
63 $form['form_textfield_test_title'] = [
64 '#type' => 'textfield',
65 '#title' => t('Textfield test for title only'),
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>',
71 $form['form_textfield_test_title_after'] = [
72 '#type' => 'textfield',
73 '#title' => t('Textfield test for title after element'),
74 '#title_display' => 'after',
76 $form['form_textfield_test_title_invisible'] = [
77 '#type' => 'textfield',
78 '#title' => t('Textfield test for invisible title'),
79 '#title_display' => 'invisible',
81 // Textfield test for title set not to display.
82 $form['form_textfield_test_title_no_show'] = [
83 '#type' => 'textfield',
85 // Checkboxes & radios with title as attribute.
86 $form['form_checkboxes_title_attribute'] = [
87 '#type' => 'checkboxes',
88 '#title' => 'Checkboxes test',
89 '#title_display' => 'attribute',
91 'first-checkbox' => 'First checkbox',
92 'second-checkbox' => 'Second checkbox',
96 $form['form_radios_title_attribute'] = [
98 '#title' => 'Radios test',
99 '#title_display' => 'attribute',
101 'first-radio' => 'First radio',
102 'second-radio' => 'Second radio',
106 $form['form_checkboxes_title_invisible'] = [
107 '#type' => 'checkboxes',
108 '#title' => 'Checkboxes test invisible',
109 '#title_display' => 'invisible',
111 'first-checkbox' => 'First checkbox',
112 'second-checkbox' => 'Second checkbox',
116 $form['form_radios_title_invisible'] = [
118 '#title' => 'Radios test invisible',
119 '#title_display' => 'invisible',
121 'first-radio' => 'First radio',
122 'second-radio' => 'Second radio',
132 public function submitForm(array &$form, FormStateInterface $form_state) {