Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestVerticalTabsForm.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 class FormTestVerticalTabsForm extends FormBase {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function getFormId() {
14     return '_form_test_vertical_tabs_form';
15   }
16
17   /**
18    * {@inheritdoc}
19    */
20   public function buildForm(array $form, FormStateInterface $form_state) {
21     $tab_count = 3;
22
23     $form['vertical_tabs'] = [
24       '#type' => 'vertical_tabs',
25       '#default_tab' => 'edit-tab' . $tab_count,
26     ];
27
28     for ($i = 1; $i <= $tab_count; $i++) {
29       $form['tab' . $i] = [
30         '#type' => 'fieldset',
31         '#title' => t('Tab @num', ['@num' => $i]),
32         '#group' => 'vertical_tabs',
33         '#access' => \Drupal::currentUser()->hasPermission('access vertical_tab_test tabs'),
34       ];
35       $form['tab' . $i]['field' . $i] = [
36         '#title' => t('Field @num', ['@num' => $i]),
37         '#type' => 'textfield',
38
39       ];
40     }
41
42     return $form;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function submitForm(array &$form, FormStateInterface $form_state) {
49     $form_state->cleanValues();
50     // This won't have a proper JSON header, but Drupal doesn't check for that
51     // anyway so this is fine until it's replaced with a JsonResponse.
52     print Json::encode($form_state->getValues());
53     exit;
54   }
55
56 }