Version 1
[yaffs-website] / web / core / modules / system / tests / modules / batch_test / src / Form / BatchTestSimpleForm.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_simple_form.
10  */
11 class BatchTestSimpleForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'batch_test_simple_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state) {
24     $form['batch'] = [
25       '#type' => 'select',
26       '#title' => 'Choose batch',
27       '#options' => [
28         'batch_0' => 'batch 0',
29         'batch_1' => 'batch 1',
30         'batch_2' => 'batch 2',
31         'batch_3' => 'batch 3',
32         'batch_4' => 'batch 4',
33       ],
34     ];
35     $form['submit'] = [
36       '#type' => 'submit',
37       '#value' => 'Submit',
38     ];
39
40     return $form;
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function submitForm(array &$form, FormStateInterface $form_state) {
47     batch_test_stack(NULL, TRUE);
48
49     $function = '_batch_test_' . $form_state->getValue('batch');
50     batch_set($function());
51
52     $form_state->setRedirect('batch_test.redirect');
53   }
54
55 }