function template_preprocess_container

Same name in other branches
  1. 9 core/includes/theme.inc \template_preprocess_container()
  2. 10 core/includes/theme.inc \template_preprocess_container()
  3. 11.x core/includes/theme.inc \template_preprocess_container()

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.
1 string reference to 'template_preprocess_container'
RegistryTest::testThemeTemplatesRegisteredByModules in core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php
Tests theme-provided templates that are registered by modules.

File

core/includes/theme.inc, line 1164

Code

function template_preprocess_container(&$variables) {
    $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.