function form_pre_render_details

Adds members of this group as actual elements for rendering.

Parameters

$element: An associative array containing the properties and children of the details.

Return value

The modified element with all group members.

Related topics

1 string reference to 'form_pre_render_details'
system_element_info in drupal/core/modules/system/system.module
Implements hook_element_info().

File

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

Code

function form_pre_render_details($element) {

  // The .form-wrapper class is required for #states to treat details like
  // containers.
  if (!isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = array();
  }

  // Collapsible details.
  if (!empty($element['#collapsible'])) {
    $element['#attached']['library'][] = array(
      'system',
      'drupal.collapse',
    );
    $element['#attributes']['class'][] = 'collapsible';
  }
  if (empty($element['#collapsed'])) {
    $element['#attributes']['open'] = 'open';
  }

  // Details may be rendered outside of a Form API context.
  if (!isset($element['#parents']) || !isset($element['#groups'])) {
    return $element;
  }

  // Inject group member elements belonging to this group.
  $parents = implode('][', $element['#parents']);
  $children = element_children($element['#groups'][$parents]);
  if (!empty($children)) {
    foreach ($children as $key) {

      // Break references and indicate that the element should be rendered as
      // group member.
      $child = (array) $element['#groups'][$parents][$key];
      $child['#group_details'] = TRUE;

      // Inject the element as new child element.
      $element[] = $child;
      $sort = TRUE;
    }

    // Re-sort the element's children if we injected group member elements.
    if (isset($sort)) {
      $element['#sorted'] = FALSE;
    }
  }
  if (isset($element['#group'])) {
    $group = $element['#group'];

    // If this element belongs to a group, but the group-holding element does
    // not exist, we need to render it (at its original location).
    if (!isset($element['#groups'][$group]['#group_exists'])) {

      // Intentionally empty to clarify the flow; we simply return $element.
    }
    elseif (!empty($element['#group_details'])) {

      // Intentionally empty to clarify the flow; we simply return $element.
    }
    elseif (element_children($element['#groups'][$group])) {
      $element['#printed'] = TRUE;
    }
  }
  return $element;
}