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

 

 

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

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

Web Posts

Search

Page Facebook