Projet

Général

Profil

Paste
Télécharger (3,22 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / includes / process.inc @ 01f36513

1
<?php
2

    
3
/**
4
 * @file
5
 * process.inc
6
 *
7
 * Contains various implementations for #process callbacks on elements.
8
 */
9

    
10
/**
11
 * Implements hook_form_process().
12
 */
13
function bootstrap_form_process($element, &$form_state, &$form) {
14
  if (!empty($element['#bootstrap_ignore_process'])) {
15
    return $element;
16
  }
17

    
18
  if (!empty($element['#attributes']['class']) && is_array($element['#attributes']['class'])) {
19
    $key = array_search('container-inline', $element['#attributes']['class']);
20
    if ($key !== FALSE) {
21
      $element['#attributes']['class'][$key] = 'form-inline';
22
    }
23

    
24
    if (in_array('form-wrapper', $element['#attributes']['class'])) {
25
      $element['#attributes']['class'][] = 'form-group';
26
    }
27
  }
28

    
29
  // Automatically inject the nearest button found after this element if
30
  // #input_group_button exists.
31
  if (!empty($element['#input_group_button'])) {
32
    // Obtain the parent array to limit search.
33
    $array_parents = array();
34
    if (!empty($element['#array_parents'])) {
35
      $array_parents += $element['#array_parents'];
36
      // Remove the current element from the array.
37
      array_pop($array_parents);
38
    }
39

    
40
    // If element is nested, return the referenced parent from the form.
41
    if (!empty($array_parents)) {
42
      $parent = &drupal_array_get_nested_value($form, $array_parents);
43
    }
44
    // Otherwise return the complete form.
45
    else {
46
      $parent = &$form;
47
    }
48

    
49
    // Ignore buttons before we find the element in the form.
50
    $found_current_element = FALSE;
51
    foreach (element_children($parent, TRUE) as $child) {
52
      if ($parent[$child] === $element) {
53
        $found_current_element = TRUE;
54
        continue;
55
      }
56

    
57
      if ($found_current_element && _bootstrap_is_button($parent[$child]) && (!isset($parent[$child]['#access']) || !!$parent[$child]['#access'])) {
58
        $element['#field_suffix'] = drupal_render($parent[$child]);
59
        break;
60
      }
61
    }
62
  }
63

    
64
  return $element;
65
}
66

    
67
/**
68
 * Implements hook_form_process_HOOK().
69
 */
70
function bootstrap_form_process_actions($element, &$form_state, &$form) {
71
  $element['#attributes']['class'][] = 'form-actions';
72

    
73
  if (!empty($element['#bootstrap_ignore_process'])) {
74
    return $element;
75
  }
76

    
77
  foreach (element_children($element) as $child) {
78
    _bootstrap_iconize_button($element[$child]);
79
  }
80
  return $element;
81
}
82

    
83
/**
84
 * Implements hook_form_process_HOOK().
85
 */
86
function bootstrap_form_process_text_format($element, &$form_state, &$form) {
87
  if (!empty($element['#bootstrap_ignore_process'])) {
88
    return $element;
89
  }
90

    
91
  // Provide smart description on the value text area.
92
  bootstrap_element_smart_description($element, $element['value']);
93

    
94
  // Allow the elements inside to be displayed inline.
95
  $element['format']['#attributes']['class'][] = 'form-inline';
96

    
97
  // Remove the cluttering guidelines; they can be viewed on a separate page.
98
  $element['format']['guidelines']['#access'] = FALSE;
99

    
100
  // Hide the select label.
101
  $element['format']['format']['#title_display'] = 'none';
102

    
103
  // Make the select element smaller using a Bootstrap class.
104
  $element['format']['format']['#attributes']['class'][] = 'input-sm';
105

    
106
  // Support the Bootstrap Select plugin if it is used.
107
  $element['format']['format']['#attributes']['data-style'] = 'btn-sm btn-default';
108

    
109
  return $element;
110
}