Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
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

 

 

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon