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, TRUE) 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]) && (!isset($parent[$child]['#access']) || !!$parent[$child]['#access'])) {
|
57
|
$element['#field_suffix'] = drupal_render($parent[$child]);
|
58
|
break;
|
59
|
}
|
60
|
}
|
61
|
}
|
62
|
|
63
|
return $element;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Implements hook_form_process_HOOK().
|
68
|
*/
|
69
|
function bootstrap_form_process_actions($element, &$form_state, &$form) {
|
70
|
$element['#attributes']['class'][] = 'form-actions';
|
71
|
|
72
|
if (!empty($element['#bootstrap_ignore_process'])) {
|
73
|
return $element;
|
74
|
}
|
75
|
|
76
|
foreach (element_children($element) as $child) {
|
77
|
_bootstrap_iconize_button($element[$child]);
|
78
|
}
|
79
|
return $element;
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Implements hook_form_process_HOOK().
|
84
|
*/
|
85
|
function bootstrap_form_process_text_format($element, &$form_state, &$form) {
|
86
|
if (!empty($element['#bootstrap_ignore_process'])) {
|
87
|
return $element;
|
88
|
}
|
89
|
|
90
|
// Provide smart description on the value text area.
|
91
|
bootstrap_element_smart_description($element, $element['value']);
|
92
|
|
93
|
// Allow the elements inside to be displayed inline.
|
94
|
$element['format']['#attributes']['class'][] = 'form-inline';
|
95
|
|
96
|
// Remove the cluttering guidelines; they can be viewed on a separate page.
|
97
|
$element['format']['guidelines']['#access'] = FALSE;
|
98
|
|
99
|
// Hide the select label.
|
100
|
$element['format']['format']['#title_display'] = 'none';
|
101
|
|
102
|
// Make the select element smaller using a Bootstrap class.
|
103
|
$element['format']['format']['#attributes']['class'][] = 'input-sm';
|
104
|
|
105
|
// Support the Bootstrap Select plugin if it is used.
|
106
|
$element['format']['format']['#attributes']['data-style'] = 'btn-sm btn-default';
|
107
|
|
108
|
return $element;
|
109
|
}
|