class VerticalTabsDemo

Implements the vertical tabs demo form controller.

This example demonstrates the use of \Drupal\Core\Render\Element\VerticalTabs to group input elements according category.

Hierarchy

Expanded class hierarchy of VerticalTabsDemo

See also

\Drupal\Core\Form\FormBase

\Drupal\Core\Form\ConfigFormBase

1 string reference to 'VerticalTabsDemo'
form_api_example.routing.yml in modules/form_api_example/form_api_example.routing.yml
modules/form_api_example/form_api_example.routing.yml

File

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

Namespace

Drupal\form_api_example\Form
View source
class VerticalTabsDemo extends DemoBase {
  
  /**
   * Build the form.
   *
   * @inheritdoc
   */
  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;
  }
  
  /**
   * Getter method for Form ID.
   *
   * @inheritdoc
   */
  public function getFormId() {
    return 'form_api_example_vertical_tabs_demo';
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
DemoBase::submitForm public function Implements a form submit handler. 2
VerticalTabsDemo::buildForm public function Build the form.
VerticalTabsDemo::getFormId public function Getter method for Form ID.