You are here

public function AjaxTestDialogForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestDialogForm.php \Drupal\ajax_test\Form\AjaxTestDialogForm::buildForm()
  2. 10 core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestDialogForm.php \Drupal\ajax_test\Form\AjaxTestDialogForm::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_test/src/Form/AjaxTestDialogForm.php, line 29

Class

AjaxTestDialogForm
Dummy form for testing DialogRenderer with _form routes.

Namespace

Drupal\ajax_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // In order to use WebTestBase::drupalPostAjaxForm() to POST from a link, we need
  // to have a dummy field we can set in WebTestBase::drupalPostForm() else it won't
  // submit anything.
  $form['textfield'] = [
    '#type' => 'hidden',
  ];
  $form['button1'] = [
    '#type' => 'submit',
    '#name' => 'button1',
    '#value' => 'Button 1 (modal)',
    '#ajax' => [
      'callback' => '::modal',
    ],
  ];
  $form['button2'] = [
    '#type' => 'submit',
    '#name' => 'button2',
    '#value' => 'Button 2 (non-modal)',
    '#ajax' => [
      'callback' => '::nonModal',
    ],
  ];
  return $form;
}