function BatchTestMultiStepForm::buildForm

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm::buildForm()
  2. 10 core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm::buildForm()
  3. 11.x core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm::buildForm()

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

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