fe2d02c5f13164e0b4768090d60f30a8d2c90679
[yaffs-website] / web / core / modules / system / tests / modules / batch_test / src / Form / BatchTestChainedForm.php
1 <?php
2
3 namespace Drupal\batch_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Generate form of id batch_test_chained_form.
10  */
11 class BatchTestChainedForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'batch_test_chained_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state) {
24     // This value is used to test that $form_state persists through batched
25     // submit handlers.
26     $form['value'] = [
27       '#type' => 'textfield',
28       '#title' => 'Value',
29       '#default_value' => 1,
30     ];
31     $form['submit'] = [
32       '#type' => 'submit',
33       '#value' => 'Submit',
34     ];
35     $form['#submit'] = [
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',
40     ];
41     return $form;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function submitForm(array &$form, FormStateInterface $form_state) {
48   }
49
50   /**
51    * Form submission handler #1 for batch_test_chained_form
52    */
53   public static function batchTestChainedFormSubmit1($form, FormStateInterface $form_state) {
54     batch_test_stack(NULL, TRUE);
55
56     batch_test_stack('submit handler 1');
57     batch_test_stack('value = ' . $form_state->getValue('value'));
58
59     $value = &$form_state->getValue('value');
60     $value++;
61     batch_set(_batch_test_batch_1());
62
63     $form_state->setRedirect('batch_test.redirect');
64   }
65
66   /**
67    * Form submission handler #2 for batch_test_chained_form
68    */
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'));
72
73     $value = &$form_state->getValue('value');
74     $value++;
75     batch_set(_batch_test_batch_2());
76
77     $form_state->setRedirect('batch_test.redirect');
78   }
79
80   /**
81    * Form submission handler #3 for batch_test_chained_form
82    */
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'));
86
87     $value = &$form_state->getValue('value');
88     $value++;
89
90     $form_state->setRedirect('batch_test.redirect');
91   }
92
93   /**
94    * Form submission handler #4 for batch_test_chained_form
95    */
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'));
99
100     $value = &$form_state->getValue('value');
101     $value++;
102     batch_set(_batch_test_batch_3());
103
104     $form_state->setRedirect('batch_test.redirect');
105   }
106
107 }