Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / includes / process.inc @ 7547bb19

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

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

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

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

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

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

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

    
56
      if ($found_current_element && _bootstrap_is_button($parent[$child])) {
57
        _bootstrap_iconize_button($parent[$child]);
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
}