VerticalTabsDemo.php in Examples for Developers 3.x
File
modules/form_api_example/src/Form/VerticalTabsDemo.php
View source
<?php
namespace Drupal\form_api_example\Form;
use Drupal\Core\Form\FormStateInterface;
class VerticalTabsDemo extends DemoBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$form['description'] = [
'#type' => 'item',
'#markup' => $this
->t('This example demonstrates the use of vertical tabs to group elements.'),
];
$form['information'] = [
'#type' => 'vertical_tabs',
'#default_tab' => 'edit-publication',
];
$form['author'] = [
'#type' => 'details',
'#title' => 'Author',
'#group' => 'information',
];
$form['author']['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
];
$form['publication'] = [
'#type' => 'details',
'#title' => $this
->t('Publication'),
'#group' => 'information',
];
$form['publication']['publisher'] = [
'#type' => 'textfield',
'#title' => $this
->t('Publisher'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}
public function getFormId() {
return 'form_api_example_vertical_tabs_demo';
}
}