function ThemePreprocess::preprocessContainer

Prepares variables for container templates.

Default template: container.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #id, #attributes, #children.

File

core/lib/Drupal/Core/Theme/ThemePreprocess.php, line 48

Class

ThemePreprocess
Preprocess for common/core theme templates.

Namespace

Drupal\Core\Theme

Code

public function preprocessContainer(array &$variables) : void {
    $variables['has_parent'] = FALSE;
    $element = $variables['element'];
    // Ensure #attributes is set.
    $element += [
        '#attributes' => [],
    ];
    // Special handling for form elements.
    if (isset($element['#array_parents'])) {
        // Assign an html ID.
        if (!isset($element['#attributes']['id'])) {
            $element['#attributes']['id'] = $element['#id'];
        }
        $variables['has_parent'] = TRUE;
    }
    $variables['children'] = $element['#children'];
    $variables['attributes'] = $element['#attributes'];
}

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