function ElementsFieldsetTest::buildForm

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Form/ElementsFieldsetTest.php \Drupal\Tests\system\Kernel\Form\ElementsFieldsetTest::buildForm()
  2. 11.x core/modules/system/tests/src/Kernel/Form/ElementsFieldsetTest.php \Drupal\Tests\system\Kernel\Form\ElementsFieldsetTest::buildForm()

Overrides FormInterface::buildForm

File

core/modules/system/tests/src/Kernel/Form/ElementsFieldsetTest.php, line 34

Class

ElementsFieldsetTest
Tests fieldset element rendering and description placement.

Namespace

Drupal\Tests\system\Kernel\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['fieldset_default'] = [
        '#type' => 'fieldset',
        '#title' => 'Fieldset title for default description display',
        '#description' => 'Fieldset description for default description display.',
    ];
    $form['meta_default'] = [
        '#type' => 'container',
        '#title' => 'Group element',
        '#group' => 'fieldset_default',
    ];
    $form['meta_default']['element'] = [
        '#type' => 'textfield',
        '#title' => 'Nested text field inside meta_default element',
    ];
    $form['fieldset_before'] = [
        '#type' => 'fieldset',
        '#title' => 'Fieldset title for description displayed before element',
        '#description' => 'Fieldset description for description displayed before element.',
        '#description_display' => 'before',
    ];
    $form['meta_before'] = [
        '#type' => 'container',
        '#title' => 'Group element',
        '#group' => 'fieldset_before',
    ];
    $form['meta_before']['element'] = [
        '#type' => 'textfield',
        '#title' => 'Nested text field inside meta_before element',
    ];
    $form['fieldset_after'] = [
        '#type' => 'fieldset',
        '#title' => 'Fieldset title for description displayed after element',
        '#description' => 'Fieldset description for description displayed after element.',
        '#description_display' => 'after',
    ];
    $form['meta_after'] = [
        '#type' => 'container',
        '#title' => 'Group element',
        '#group' => 'fieldset_after',
    ];
    $form['meta_after']['element'] = [
        '#type' => 'textfield',
        '#title' => 'Nested text field inside meta_after element',
    ];
    $form['fieldset_invisible'] = [
        '#type' => 'fieldset',
        '#title' => 'Fieldset title for description displayed as visually hidden element',
        '#description' => 'Fieldset description for description displayed as visually hidden element.',
        '#description_display' => 'invisible',
    ];
    $form['meta_invisible'] = [
        '#type' => 'container',
        '#title' => 'Group element',
        '#group' => 'fieldset_invisible',
    ];
    $form['meta_invisible']['element'] = [
        '#type' => 'textfield',
        '#title' => 'Nested text field inside meta_invisible element',
    ];
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.