function VerticalTabs::processVerticalTabs

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/VerticalTabs.php \Drupal\Core\Render\Element\VerticalTabs::processVerticalTabs()
  2. 8.9.x core/lib/Drupal/Core/Render/Element/VerticalTabs.php \Drupal\Core\Render\Element\VerticalTabs::processVerticalTabs()
  3. 10 core/lib/Drupal/Core/Render/Element/VerticalTabs.php \Drupal\Core\Render\Element\VerticalTabs::processVerticalTabs()

Creates a group formatted as vertical tabs.

Parameters

array $element: An associative array containing the properties and children of the details element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

Return value

array The processed element.

File

core/lib/Drupal/Core/Render/Element/VerticalTabs.php, line 102

Class

VerticalTabs
Provides a render element for vertical tabs in a form.

Namespace

Drupal\Core\Render\Element

Code

public static function processVerticalTabs(&$element, FormStateInterface $form_state, &$complete_form) {
    if (isset($element['#access']) && !$element['#access']) {
        return $element;
    }
    // Inject a new details as child, so that form_process_details() processes
    // this details element like any other details.
    $element['group'] = [
        '#type' => 'details',
        '#theme_wrappers' => [],
        '#parents' => $element['#parents'],
    ];
    // Add an invisible label for accessibility.
    if (!isset($element['#title'])) {
        $element['#title'] = t('Vertical Tabs');
        $element['#title_display'] = 'invisible';
    }
    $element['#attached']['library'][] = 'core/drupal.vertical-tabs';
    // The JavaScript stores the currently selected tab in this hidden
    // field so that the active tab can be restored the next time the
    // form is rendered, e.g. on preview pages or when form validation
    // fails.
    $name = implode('__', $element['#parents']);
    if ($form_state->hasValue($name . '__active_tab')) {
        $element['#default_tab'] = $form_state->getValue($name . '__active_tab');
    }
    $element[$name . '__active_tab'] = [
        '#type' => 'hidden',
        '#default_value' => $element['#default_tab'],
        '#attributes' => [
            'class' => [
                'vertical-tabs__active-tab',
            ],
        ],
    ];
    // Clean up the active tab value so it's not accidentally stored in
    // settings forms.
    $form_state->addCleanValueKey($name . '__active_tab');
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.