You are here

public function AjaxFormBlock::buildForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::buildForm()
  2. 9 core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::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/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php, line 88

Class

AjaxFormBlock
Provides an AJAX form block.

Namespace

Drupal\ajax_forms_test\Plugin\Block

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['test1'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Test 1'),
    '#required' => TRUE,
    '#options' => [
      'option1' => $this
        ->t('Option 1'),
      'option2' => $this
        ->t('Option 2'),
    ],
    '#ajax' => [
      'callback' => '::updateOptions',
      'wrapper' => 'edit-test1-wrapper',
    ],
    '#prefix' => '<div id="edit-test1-wrapper">',
    '#suffix' => '</div>',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}