class BatchTestMultiStepForm
Same name and namespace in other branches
- 11.x core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm
- 10 core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm
- 8.9.x core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php \Drupal\batch_test\Form\BatchTestMultiStepForm
Generate form of id batch_test_multistep_form.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\batch_test\Form\BatchTestMultiStepForm extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of BatchTestMultiStepForm
1 string reference to 'BatchTestMultiStepForm'
- batch_test.routing.yml in core/
modules/ system/ tests/ modules/ batch_test/ batch_test.routing.yml - core/modules/system/tests/modules/batch_test/batch_test.routing.yml
File
-
core/
modules/ system/ tests/ modules/ batch_test/ src/ Form/ BatchTestMultiStepForm.php, line 13
Namespace
Drupal\batch_test\FormView source
class BatchTestMultiStepForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'batch_test_multistep_form';
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
batch_test_stack(NULL, TRUE);
$step = $form_state->get('step');
switch ($step) {
case 1:
batch_set(_batch_test_batch_1());
break;
case 2:
batch_set(_batch_test_batch_2());
break;
}
if ($step < 2) {
$form_state->set('step', ++$step);
$form_state->setRebuild();
}
$form_state->setRedirect('batch_test.redirect');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.