Skip to main content
Category:

in this tuto, I'll show you how to use  \Drupal\Core\Render\Element\VerticalTabs  to group input elements according category. using '#type' => 'vertical_tabs' .

Add the following code inside a function where you want to create vertical tabs elements : 

$form['contactform'] = [
  '#type' => 'vertical_tabs',
];

$form['info'] = [
  '#type' => 'details',
  '#title' => 'Informations',
  '#group' => 'contactform',
];

$form['info']['name'] = [
  '#type' => 'textfield',
  '#title' => $this->t('Name'),
];
$form['info']['message'] = [
  '#type' => 'textarea',
  '#title' => $this->t('Message'),
];

$form['publication'] = [
  '#type' => 'details',
  '#title' => $this->t('Publication'),
  '#group' => 'contactform',
];

$form['publication']['publisher'] = [
  '#type' => 'textfield',
  '#title' => $this->t('Publisher'),
];

$form['publication']['publisher_info'] = [
  '#type' => 'textarea',
  '#title' => $this->t('Message'),
];

 

And this is my final output:

vertical tabs form api

 

 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook