function VerticalTabsDemo::buildForm

Same name and namespace in other branches
  1. 4.0.x modules/form_api_example/src/Form/VerticalTabsDemo.php \Drupal\form_api_example\Form\VerticalTabsDemo::buildForm()

Build the form.

@inheritdoc

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

modules/form_api_example/src/Form/VerticalTabsDemo.php, line 23

Class

VerticalTabsDemo
Implements the vertical tabs demo form controller.

Namespace

Drupal\form_api_example\Form

Code

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;
}