You are here

public function BatchTestMultiStepForm::buildForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm::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/batch_test/src/Form/BatchTestMultiStepForm.php, line 25

Class

BatchTestMultiStepForm
Generate form of id batch_test_multistep_form.

Namespace

Drupal\batch_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $step = $form_state
    ->get('step');
  if (empty($step)) {
    $step = 1;
    $form_state
      ->set('step', $step);
  }
  $form['step_display'] = [
    '#markup' => 'step ' . $step . '<br/>',
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'Submit',
  ];

  // This is a POST form with multiple steps that does not transition from one
  // step to the next via POST requests, but via GET requests, because it uses
  // Batch API to advance through the steps.
  $form['#cache']['max-age'] = 0;
  return $form;
}