a30094f79b6202a8bb53939e7a4f58f1b1381487
[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  * @internal
12  */
13 class BatchTestChainedForm extends FormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'batch_test_chained_form';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function buildForm(array $form, FormStateInterface $form_state) {
26     // This value is used to test that $form_state persists through batched
27     // submit handlers.
28     $form['value'] = [
29       '#type' => 'textfield',
30       '#title' => 'Value',
31       '#default_value' => 1,
32     ];
33     $form['submit'] = [
34       '#type' => 'submit',
35       '#value' => 'Submit',
36     ];
37     $form['#submit'] = [
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',
42     ];
43     return $form;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function submitForm(array &$form, FormStateInterface $form_state) {
50   }
51
52   /**
53    * Form submission handler #1 for batch_test_chained_form
54    */
55   public static function batchTestChainedFormSubmit1($form, FormStateInterface $form_state) {
56     batch_test_stack(NULL, TRUE);
57
58     batch_test_stack('submit handler 1');
59     batch_test_stack('value = ' . $form_state->getValue('value'));
60
61     $value = &$form_state->getValue('value');
62     $value++;
63     batch_set(_batch_test_batch_1());
64
65     $form_state->setRedirect('batch_test.redirect');
66   }
67
68   /**
69    * Form submission handler #2 for batch_test_chained_form
70    */
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'));
74
75     $value = &$form_state->getValue('value');
76     $value++;
77     batch_set(_batch_test_batch_2());
78
79     $form_state->setRedirect('batch_test.redirect');
80   }
81
82   /**
83    * Form submission handler #3 for batch_test_chained_form
84    */
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'));
88
89     $value = &$form_state->getValue('value');
90     $value++;
91
92     $form_state->setRedirect('batch_test.redirect');
93   }
94
95   /**
96    * Form submission handler #4 for batch_test_chained_form
97    */
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'));
101
102     $value = &$form_state->getValue('value');
103     $value++;
104     batch_set(_batch_test_batch_3());
105
106     $form_state->setRedirect('batch_test.redirect');
107   }
108
109 }