function AjaxFormBlock::buildForm

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::buildForm()
  2. 8.9.x core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::buildForm()
  3. 10 core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php \Drupal\ajax_forms_test\Plugin\Block\AjaxFormBlock::buildForm()

Overrides FormInterface::buildForm

File

core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php, line 89

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

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