You are here

public function Select2OptgroupForm::buildForm in Select 2 8

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

tests/modules/select2_form_test/src/Form/Select2OptgroupForm.php, line 26

Class

Select2OptgroupForm
Test form to test the select2 element.

Namespace

Drupal\select2_form_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $customize = FALSE) {
  $form['select2_optgroups'] = [
    '#type' => 'select2',
    '#title' => 'Optgroups',
    '#options' => [
      0 => 'Foo',
      1 => 'Bar',
      'Baba' => [
        3 => 'Nana',
      ],
      2 => 'Gaga',
    ],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'Submit',
  ];
  return $form;
}