You are here

public function ElementsFieldsetTest::buildForm in Drupal 10

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

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

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

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;
}