function JsAjaxTestForm::buildForm

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

Form for testing the addition of various types of elements via Ajax.

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/js_ajax_test/src/Form/JsAjaxTestForm.php, line 27

Class

JsAjaxTestForm
Test form for js_ajax_test

Namespace

Drupal\js_ajax_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#attached']['library'][] = 'js_ajax_test/ajax';
  $form['custom']['#prefix'] = '<div id="js_ajax_test_form_wrapper">';
  $form['custom']['#suffix'] = '</div>';
  // Button to test for the waitForButton() assertion.
  $form['test_button'] = [
    '#type' => 'submit',
    '#value' => $this->t('Add button'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => [
        static::class,
        'addButton',
      ],
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_ajax_test_form_wrapper',
    ],
  ];
  return $form;
}

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