1 |
87dbc3bf
|
Benjamin Luce
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
function bootstrap_form_element(&$variables) {
|
11 |
|
|
$element = &$variables['element'];
|
12 |
|
|
$is_checkbox = FALSE;
|
13 |
|
|
$is_radio = FALSE;
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
$element += array(
|
18 |
|
|
'#title_display' => 'before',
|
19 |
|
|
);
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
if (isset($element['#markup']) && !empty($element['#id'])) {
|
23 |
|
|
$attributes['id'] = $element['#id'];
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
if (isset($element['#parents']) && form_get_error($element)) {
|
28 |
|
|
$attributes['class'][] = 'error';
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
if (!empty($element['#type'])) {
|
32 |
|
|
$attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
|
33 |
|
|
}
|
34 |
|
|
if (!empty($element['#name'])) {
|
35 |
|
|
$attributes['class'][] = 'form-item-' . strtr($element['#name'], array(
|
36 |
|
|
' ' => '-',
|
37 |
|
|
'_' => '-',
|
38 |
|
|
'[' => '-',
|
39 |
|
|
']' => '',
|
40 |
|
|
));
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
if (!empty($element['#attributes']['disabled'])) {
|
44 |
|
|
$attributes['class'][] = 'form-disabled';
|
45 |
|
|
}
|
46 |
|
|
if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
|
47 |
|
|
$attributes['class'][] = 'form-autocomplete';
|
48 |
|
|
}
|
49 |
|
|
$attributes['class'][] = 'form-item';
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
if (isset($element['#type'])) {
|
53 |
|
|
if ($element['#type'] == "radio") {
|
54 |
|
|
$attributes['class'][] = 'radio';
|
55 |
|
|
$is_radio = TRUE;
|
56 |
|
|
}
|
57 |
|
|
elseif ($element['#type'] == "checkbox") {
|
58 |
|
|
$attributes['class'][] = 'checkbox';
|
59 |
|
|
$is_checkbox = TRUE;
|
60 |
|
|
}
|
61 |
|
|
else {
|
62 |
|
|
$attributes['class'][] = 'form-group';
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
$description = FALSE;
|
67 |
|
|
$tooltip = FALSE;
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
if (!empty($element['#description'])) {
|
71 |
|
|
$description = $element['#description'];
|
72 |
|
|
if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description) && strlen($description) <= 200) {
|
73 |
|
|
$tooltip = TRUE;
|
74 |
|
|
$attributes['data-toggle'] = 'tooltip';
|
75 |
|
|
$attributes['title'] = $description;
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
if (!isset($element['#title'])) {
|
83 |
|
|
$element['#title_display'] = 'none';
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
$prefix = '';
|
87 |
|
|
$suffix = '';
|
88 |
|
|
if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) {
|
89 |
|
|
|
90 |
|
|
if (!empty($element['#input_group'])) {
|
91 |
|
|
$prefix .= '<div class="input-group">';
|
92 |
|
|
$prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : '';
|
93 |
|
|
$suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : '';
|
94 |
|
|
$suffix .= '</div>';
|
95 |
|
|
}
|
96 |
|
|
else {
|
97 |
|
|
$prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : '';
|
98 |
|
|
$suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : '';
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
switch ($element['#title_display']) {
|
103 |
|
|
case 'before':
|
104 |
|
|
case 'invisible':
|
105 |
|
|
$output .= ' ' . theme('form_element_label', $variables);
|
106 |
|
|
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
|
107 |
|
|
break;
|
108 |
|
|
|
109 |
|
|
case 'after':
|
110 |
|
|
if ($is_radio || $is_checkbox) {
|
111 |
|
|
$output .= ' ' . $prefix . $element['#children'] . $suffix;
|
112 |
|
|
}
|
113 |
|
|
else {
|
114 |
|
|
$variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix;
|
115 |
|
|
}
|
116 |
|
|
$output .= ' ' . theme('form_element_label', $variables) . "\n";
|
117 |
|
|
break;
|
118 |
|
|
|
119 |
|
|
case 'none':
|
120 |
|
|
case 'attribute':
|
121 |
|
|
|
122 |
|
|
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
|
123 |
|
|
break;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
if ($description && !$tooltip) {
|
127 |
|
|
$output .= '<p class="help-block">' . $element['#description'] . "</p>\n";
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
$output .= "</div>\n";
|
131 |
|
|
|
132 |
|
|
return $output;
|
133 |
|
|
} |