function FormTestVerticalTabsWithSummaryForm::buildForm
Form constructor.
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
-
core/
modules/ system/ tests/ modules/ form_test/ src/ Form/ FormTestVerticalTabsWithSummaryForm.php, line 27
Class
- FormTestVerticalTabsWithSummaryForm
- Builds a simple form to test vertical-tabs form element with tab summaries.
Namespace
Drupal\form_test\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['information'] = [
'#type' => 'vertical_tabs',
'#default_tab' => 'edit-tab1',
];
$form['tab1'] = [
'#type' => 'details',
'#title' => $this->t('Tab 1'),
'#group' => 'information',
];
$form['tab1']['field1'] = [
'#type' => 'textfield',
'#title' => $this->t('Field 1'),
];
$form['tab2'] = [
'#type' => 'details',
'#title' => $this->t('Tab 2'),
'#group' => 'information',
];
$form['tab2']['field2'] = [
'#type' => 'textfield',
'#title' => $this->t('Field 2'),
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#button_type' => 'primary',
];
// Attach the library that sets the vertical tab summaries.
$form['#attached']['library'][] = 'form_test/form_test';
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.