3 namespace Drupal\batch_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Generate form of id batch_test_chained_form.
11 class BatchTestChainedForm extends FormBase {
16 public function getFormId() {
17 return 'batch_test_chained_form';
23 public function buildForm(array $form, FormStateInterface $form_state) {
24 // This value is used to test that $form_state persists through batched
27 '#type' => 'textfield',
29 '#default_value' => 1,
36 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit1',
37 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit2',
38 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit3',
39 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit4',
47 public function submitForm(array &$form, FormStateInterface $form_state) {
51 * Form submission handler #1 for batch_test_chained_form
53 public static function batchTestChainedFormSubmit1($form, FormStateInterface $form_state) {
54 batch_test_stack(NULL, TRUE);
56 batch_test_stack('submit handler 1');
57 batch_test_stack('value = ' . $form_state->getValue('value'));
59 $value = &$form_state->getValue('value');
61 batch_set(_batch_test_batch_1());
63 $form_state->setRedirect('batch_test.redirect');
67 * Form submission handler #2 for batch_test_chained_form
69 public static function batchTestChainedFormSubmit2($form, FormStateInterface $form_state) {
70 batch_test_stack('submit handler 2');
71 batch_test_stack('value = ' . $form_state->getValue('value'));
73 $value = &$form_state->getValue('value');
75 batch_set(_batch_test_batch_2());
77 $form_state->setRedirect('batch_test.redirect');
81 * Form submission handler #3 for batch_test_chained_form
83 public static function batchTestChainedFormSubmit3($form, FormStateInterface $form_state) {
84 batch_test_stack('submit handler 3');
85 batch_test_stack('value = ' . $form_state->getValue('value'));
87 $value = &$form_state->getValue('value');
90 $form_state->setRedirect('batch_test.redirect');
94 * Form submission handler #4 for batch_test_chained_form
96 public static function batchTestChainedFormSubmit4($form, FormStateInterface $form_state) {
97 batch_test_stack('submit handler 4');
98 batch_test_stack('value = ' . $form_state->getValue('value'));
100 $value = &$form_state->getValue('value');
102 batch_set(_batch_test_batch_3());
104 $form_state->setRedirect('batch_test.redirect');