function template_preprocess_details

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

Prepares variables for details element templates.

Default template: details.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #attributes, #children, #description, #required, #summary_attributes, #title, #value.

File

core/includes/form.inc, line 241

Code

function template_preprocess_details(&$variables) {
    $element = $variables['element'];
    $variables['attributes'] = $element['#attributes'];
    $variables['summary_attributes'] = new Attribute($element['#summary_attributes']);
    if (!empty($element['#title'])) {
        $variables['summary_attributes']['role'] = 'button';
        if (!empty($element['#attributes']['id'])) {
            $variables['summary_attributes']['aria-controls'] = $element['#attributes']['id'];
        }
        $variables['summary_attributes']['aria-expanded'] = !empty($element['#attributes']['open']) ? 'true' : 'false';
        $variables['summary_attributes']['aria-pressed'] = $variables['summary_attributes']['aria-expanded'];
    }
    $variables['title'] = !empty($element['#title']) ? $element['#title'] : '';
    // If the element title is a string, wrap it a render array so that markup
    // will not be escaped (but XSS-filtered).
    if (is_string($variables['title']) && $variables['title'] !== '') {
        $variables['title'] = [
            '#markup' => $variables['title'],
        ];
    }
    $variables['description'] = !empty($element['#description']) ? $element['#description'] : '';
    $variables['children'] = isset($element['#children']) ? $element['#children'] : '';
    $variables['value'] = isset($element['#value']) ? $element['#value'] : '';
    $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
    // Suppress error messages.
    $variables['errors'] = NULL;
}

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