1 |
87dbc3bf
|
Benjamin Luce
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* process.inc
|
5 |
|
|
*
|
6 |
|
|
* Contains various implementations for #process callbacks on elements.
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Process all elements.
|
11 |
|
|
*/
|
12 |
|
|
function _bootstrap_process_element(&$element, &$form_state) {
|
13 |
|
|
if (!empty($element['#attributes']['class']) && is_array($element['#attributes']['class'])) {
|
14 |
|
|
if (in_array('container-inline', $element['#attributes']['class'])) {
|
15 |
|
|
$element['#attributes']['class'][] = 'form-inline';
|
16 |
|
|
}
|
17 |
|
|
if (in_array('form-wrapper', $element['#attributes']['class'])) {
|
18 |
|
|
$element['#attributes']['class'][] = 'form-group';
|
19 |
|
|
}
|
20 |
|
|
}
|
21 |
|
|
return $element;
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Process input elements.
|
26 |
|
|
*/
|
27 |
|
|
function _bootstrap_process_input(&$element, &$form_state) {
|
28 |
|
|
// Only add the "form-control" class for specific element input types.
|
29 |
|
|
$types = array(
|
30 |
|
|
// Core.
|
31 |
|
|
'password',
|
32 |
|
|
'password_confirm',
|
33 |
|
|
'select',
|
34 |
|
|
'textarea',
|
35 |
|
|
'textfield',
|
36 |
|
|
// Elements module.
|
37 |
|
|
'emailfield',
|
38 |
|
|
'numberfield',
|
39 |
|
|
'rangefield',
|
40 |
|
|
'searchfield',
|
41 |
|
|
'telfield',
|
42 |
|
|
'urlfield',
|
43 |
|
|
);
|
44 |
|
|
if (!empty($element['#type']) && (in_array($element['#type'], $types) || ($element['#type'] === 'file' && empty($element['#managed_file'])))) {
|
45 |
|
|
$element['#attributes']['class'][] = 'form-control';
|
46 |
|
|
}
|
47 |
|
|
return $element;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
/**
|
51 |
|
|
* Process fieldset element.
|
52 |
|
|
*/
|
53 |
|
|
function _bootstrap_process_fieldset(&$element, &$form_state) {
|
54 |
|
|
$parents = implode('][', $element['#parents']);
|
55 |
|
|
|
56 |
|
|
// Each fieldset forms a new group. The #type 'vertical_tabs' basically only
|
57 |
|
|
// injects a new fieldset.
|
58 |
|
|
$form_state['groups'][$parents]['#group_exists'] = TRUE;
|
59 |
|
|
$element['#groups'] = &$form_state['groups'];
|
60 |
|
|
|
61 |
|
|
// Process vertical tabs group member fieldsets.
|
62 |
|
|
if (isset($element['#group'])) {
|
63 |
|
|
// Add this fieldset to the defined group (by reference).
|
64 |
|
|
$element['#theme_wrappers'] = array('bootstrap_panel');
|
65 |
|
|
$group = $element['#group'];
|
66 |
|
|
$form_state['groups'][$group][] = &$element;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
// Contains form element summary functionalities.
|
70 |
|
|
$element['#attached']['library'][] = array('system', 'drupal.form');
|
71 |
|
|
|
72 |
|
|
// The .form-wrapper class is required for #states to treat fieldsets like
|
73 |
|
|
// containers.
|
74 |
|
|
if (!isset($element['#attributes']['class'])) {
|
75 |
|
|
$element['#attributes']['class'] = array();
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
return $element;
|
79 |
|
|
} |