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.
13 class BatchTestChainedForm extends FormBase {
18 public function getFormId() {
19 return 'batch_test_chained_form';
25 public function buildForm(array $form, FormStateInterface $form_state) {
26 // This value is used to test that $form_state persists through batched
29 '#type' => 'textfield',
31 '#default_value' => 1,
38 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit1',
39 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit2',
40 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit3',
41 'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit4',
49 public function submitForm(array &$form, FormStateInterface $form_state) {
53 * Form submission handler #1 for batch_test_chained_form
55 public static function batchTestChainedFormSubmit1($form, FormStateInterface $form_state) {
56 batch_test_stack(NULL, TRUE);
58 batch_test_stack('submit handler 1');
59 batch_test_stack('value = ' . $form_state->getValue('value'));
61 $value = &$form_state->getValue('value');
63 batch_set(_batch_test_batch_1());
65 $form_state->setRedirect('batch_test.redirect');
69 * Form submission handler #2 for batch_test_chained_form
71 public static function batchTestChainedFormSubmit2($form, FormStateInterface $form_state) {
72 batch_test_stack('submit handler 2');
73 batch_test_stack('value = ' . $form_state->getValue('value'));
75 $value = &$form_state->getValue('value');
77 batch_set(_batch_test_batch_2());
79 $form_state->setRedirect('batch_test.redirect');
83 * Form submission handler #3 for batch_test_chained_form
85 public static function batchTestChainedFormSubmit3($form, FormStateInterface $form_state) {
86 batch_test_stack('submit handler 3');
87 batch_test_stack('value = ' . $form_state->getValue('value'));
89 $value = &$form_state->getValue('value');
92 $form_state->setRedirect('batch_test.redirect');
96 * Form submission handler #4 for batch_test_chained_form
98 public static function batchTestChainedFormSubmit4($form, FormStateInterface $form_state) {
99 batch_test_stack('submit handler 4');
100 batch_test_stack('value = ' . $form_state->getValue('value'));
102 $value = &$form_state->getValue('value');
104 batch_set(_batch_test_batch_3());
106 $form_state->setRedirect('batch_test.redirect');