8.5.x form.inc template_preprocess_details(&$variables)
8.0.x form.inc template_preprocess_details(&$variables)
8.1.x form.inc template_preprocess_details(&$variables)
8.2.x form.inc template_preprocess_details(&$variables)
8.3.x form.inc template_preprocess_details(&$variables)
8.4.x form.inc template_preprocess_details(&$variables)
8.6.x form.inc template_preprocess_details(&$variables)

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, #open, #description, #id, #title, #value, #optional.

File

core/includes/form.inc, line 241
Functions for form and batch generation and processing.

Code

function template_preprocess_details(&$variables) {
  $element = $variables['element'];
  $variables['attributes'] = $element['#attributes'];
  $variables['summary_attributes'] = new Attribute();
  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'] : '';
  $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;
}