public function VerticalTabsDemo::buildForm in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/form_api_example/src/Form/VerticalTabsDemo.php \Drupal\form_api_example\Form\VerticalTabsDemo::buildForm()
Build the form.
@inheritdoc
Overrides FormInterface::buildForm
File
- form_api_example/
src/ Form/ VerticalTabsDemo.php, line 23
Class
- VerticalTabsDemo
- Implements the vertical tabs demo form controller.
Namespace
Drupal\form_api_example\FormCode
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',
];
// Add a submit button that handles the submission of the form.
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}