Projet

Général

Profil

Paste
Télécharger (2,05 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / theme / pre-render.inc @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * pre-render.inc
5
 *
6
 * Contains various implementations for #pre_render callbacks on elements.
7
 */
8

    
9
/**
10
 * Pre-render fieldset element.
11
 */
12
function _bootstrap_pre_render_fieldset($element) {
13
  // Fieldsets may be rendered outside of a Form API context.
14
  if (!isset($element['#parents']) || !isset($element['#groups'])) {
15
    return $element;
16
  }
17
  // Inject group member elements belonging to this group.
18
  $parents = implode('][', $element['#parents']);
19
  $children = element_children($element['#groups'][$parents]);
20
  if (!empty($children)) {
21
    if (empty($element['#default_tab'])) {
22
      $children_keys = array_values($children);
23
      $element['#default_tab'] = $element['#groups'][$parents][array_shift($children_keys)]['#id'];
24
    }
25
    foreach ($children as $key) {
26
      // Break references and indicate that the element should be rendered as
27
      // group member.
28
      $child = (array) $element['#groups'][$parents][$key];
29
      $child['#attributes']['id'] = $child['#id'];
30
      $child['#group_fieldset'] = TRUE;
31
      // Inject the element as new child element.
32
      $element[] = $child;
33

    
34
      $sort = TRUE;
35
    }
36
    // Re-sort the element's children if we injected group member elements.
37
    if (isset($sort)) {
38
      $element['#sorted'] = FALSE;
39
    }
40
  }
41

    
42
  if (isset($element['#group'])) {
43
    $group = $element['#group'];
44
    // If this element belongs to a group, but the group-holding element does
45
    // not exist, we need to render it (at its original location).
46
    if (!isset($element['#groups'][$group]['#group_exists'])) {
47
      // Intentionally empty to clarify the flow; we simply return $element.
48
    }
49
    // If we injected this element into the group, then we want to render it.
50
    elseif (!empty($element['#group_fieldset'])) {
51
      // Intentionally empty to clarify the flow; we simply return $element.
52
    }
53
    // Otherwise, this element belongs to a group and the group exists, so we do
54
    // not render it.
55
    elseif (element_children($element['#groups'][$group])) {
56
      $element['#printed'] = TRUE;
57
    }
58
  }
59

    
60
  return $element;
61
}