1 form.inc theme_details($variables)

Returns HTML to wrap children in a details element.

Used for grouped form items. Can also be used as a theme wrapper for any renderable element, to surround it with a <details> tag and add attributes such as classes or an HTML id.

Parameters

array $variables: An associative array containing:

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

Return value

string: The rendered HTML output.

Related topics

File

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

Code

function theme_details($variables) {
  $element = $variables['element'];
  // Ensure #attributes is set.
  $element += array('#attributes' => array());

  // Special handling for form elements.
  if (isset($element['#array_parents'])) {
    // Assign an HTML ID.
    if (!array_key_exists('id', $element['#attributes'])) {
      $element['#attributes']['id'] = $element['#id'];
    }
    // Add the form-wrapper class.
    if (empty($element['#attributes']['class'])) {
      $element['#attributes']['class'][] = 'form-wrapper';
    }
  }
  // Set initial collapsed/expanded display.
  if (isset($element['#open']) && $element['#open']) {
    $element['#attributes']['open'] = 'open';
  }

  $output = '<details' . backdrop_attributes($element['#attributes']) . '>';
  $output .= '<summary><span>' . $element['#summary'] . '</span></summary>';
  if (isset($element['#details']) && !empty($element['#details'])) {
    $output .= '<div class="details-content-wrapper">' . $element['#details'] . '</div>';
  }
  if (isset($element['#children']) && !empty($element['#children'])) {
    $output .= '<div class="details-child-wrapper">' . $element['#children'] . '</div>';
  }
  $output .= '</details>';

  return $output;
}