FormTestVerticalTabsForm.php in Zircon Profile 8.0
File
core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsForm.php
View source
<?php
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class FormTestVerticalTabsForm extends FormBase {
public function getFormId() {
return '_form_test_vertical_tabs_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$tab_count = 3;
$form['vertical_tabs'] = array(
'#type' => 'vertical_tabs',
'#default_tab' => 'edit-tab' . $tab_count,
);
for ($i = 1; $i <= $tab_count; $i++) {
$form['tab' . $i] = array(
'#type' => 'fieldset',
'#title' => t('Tab @num', array(
'@num' => $i,
)),
'#group' => 'vertical_tabs',
'#access' => \Drupal::currentUser()
->hasPermission('access vertical_tab_test tabs'),
);
$form['tab' . $i]['field' . $i] = array(
'#title' => t('Field @num', array(
'@num' => $i,
)),
'#type' => 'textfield',
);
}
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->cleanValues();
print Json::encode($form_state
->getValues());
exit;
}
}