3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
8 class FormTestVerticalTabsForm extends FormBase {
13 public function getFormId() {
14 return '_form_test_vertical_tabs_form';
20 public function buildForm(array $form, FormStateInterface $form_state) {
23 $form['vertical_tabs'] = [
24 '#type' => 'vertical_tabs',
25 '#default_tab' => 'edit-tab' . $tab_count,
28 for ($i = 1; $i <= $tab_count; $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'),
35 $form['tab' . $i]['field' . $i] = [
36 '#title' => t('Field @num', ['@num' => $i]),
37 '#type' => 'textfield',
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());