forked from ai-abdellah/Bootstrap-3-for-Drupal-7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.php
358 lines (291 loc) · 11.2 KB
/
template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
function boostrapdrupal_preprocess_page(&$variables) {
switch (current_path()) {
case 'user/login':
$variables['title'] = 'Accesso';
unset($variables['tabs']);
break;
case 'user/password':
$variables['title'] = 'Recupera la password';
unset($variables['tabs']);
break;
case 'contact':
$variables['title'] = 'Lascia un messaggio';
break;
}
}
function boostrapdrupal_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'boostrapdrupal') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'boostrapdrupal_preprocess_user_login'
),
);
$items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'boostrapdrupal') . '/templates',
'template' => 'user-register-form',
'preprocess functions' => array(
'boostrapdrupal_preprocess_user_register_form'
),
);
$items['user_pass'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'boostrapdrupal') . '/templates',
'template' => 'user-pass',
'preprocess functions' => array(
'boostrapdrupal_preprocess_user_pass'
),
);
return $items;
}
function boostrapdrupal_preprocess_user_login(&$variables) {
$variables['form']['#attributes']['class'][] = 'form-horizontal';
}
function boostrapdrupal_preprocess_user_register_form(&$variables) { }
function boostrapdrupal_preprocess_user_pass(&$variables) { }
function boostrapdrupal_button($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'submit';
element_set_attributes($element, array('id', 'name', 'value'));
$element['#attributes']['class'][] = 'form-' . $element['#button_type'];
$element['#attributes']['class'][] = 'btn';
if($element['#button_type'] == 'submit'){
$element['#attributes']['class'][] = 'btn-primary';
$element['#attributes']['class'][] = 'btn-lg';
}
if (!empty($element['#attributes']['disabled'])) {
$element['#attributes']['class'][] = 'form-button-disabled';
}
return '<button' . drupal_attributes($element['#attributes']) . '>'.$element['#attributes']['value'].'</button>';
}
function boostrapdrupal_textfield($variables) {
$element = $variables['element'];
$output = '';
if($element['#name'] == 'name' && current_path() == 'user/login')
$output = '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>';
$element['#attributes']['type'] = 'text';
if(isset($variables['element']['#description']))
$element['#attributes']['placeholder'] = $variables['element']['#description'];
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
_form_set_class($element, array('form-text', 'form-control', 'input-lg-3'));
$extra = '';
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
if($element['#name'] == 'name' && current_path() == 'user/login')
$output .= '</div>';
return $output . $extra;
}
function boostrapdrupal_password($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'password';
element_set_attributes($element, array('id', 'name', 'size', 'maxlength'));
_form_set_class($element, array('form-text', 'form-control'));
$output = '';
// login form adding glyphicon.
if($element['#name'] == 'pass')
$output = '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-eye-close"></span></span>';
$output .= '<input' . drupal_attributes($element['#attributes']) . ' />';
if($element['#name'] == 'pass')
$output .= '</div>';
return $output;
}
function boostrapdrupal_textarea($variables) {
$element = $variables['element'];
element_set_attributes($element, array('id', 'name', 'cols', 'rows'));
_form_set_class($element, array('form-textarea'));
$wrapper_attributes = array(
'class' => array('form-textarea-wrapper'),
);
if (!empty($element['#resizable'])) {
drupal_add_library('system', 'drupal.textarea');
$wrapper_attributes['class'][] = 'resizable';
}
$element['#attributes']['class'][] = 'form-control';
$output = '<div' . drupal_attributes($wrapper_attributes) . '>';
$output .= '<textarea' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>';
$output .= '</div>';
return $output;
}
function boostrapdrupal_form_element($variables) {
$element = &$variables['element'];
$element += array(
'#title_display' => 'before',
);
if (isset($element['#markup']) && !empty($element['#id']))
$attributes['id'] = $element['#id'];
$attributes['class'] = array('form-item');
if (!empty($element['#type']))
$attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
if (!empty($element['#name']))
$attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
if (!empty($element['#attributes']['disabled']))
$attributes['class'][] = 'form-disabled';
if (isset($element['#parents']) && form_get_error($element))
$attributes['class'][] = 'has-error';
if($element['#type'] != 'radio')
$attributes['class'][] = 'form-group';
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
if (!isset($element['#title']))
$element['#title_display'] = 'none';
$prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
$suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
switch ($element['#title_display']) {
case 'before':
case 'invisible':
$output .= ' ' . theme('form_element_label', $variables);
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
case 'after':
$output .= ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
case 'none':
case 'attribute':
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}
if (!empty($element['#description']))
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
$output .= "</div>\n";
return $output;
}
function boostrapdrupal_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'user_login') {
$form['name']['#description'] = '';
$form['pass']['#description'] = '';
}
}
function boostrapdrupal_html_head_alter(&$head_elements) {
unset($head_elements['system_meta_generator']);
}
function boostrapdrupal_js_alter(&$javascript) {
$jquery_path = drupal_get_path('theme','boostrapdrupal') . '/js/jquery-1.11.0.min.js';
$javascript[$jquery_path] = $javascript['misc/jquery.js'];
$javascript[$jquery_path]['version'] = '1.11.0';
$javascript[$jquery_path]['data'] = $jquery_path;
unset($javascript['misc/jquery.js']);
}
function boostrapdrupal_css_alter(&$css) {
$exclude = array(
'modules/field/theme/field.css' => FALSE,
'modules/node/node.css' => FALSE,
'modules/system/system.base.css' => FALSE,
'modules/system/system.menus.css' => FALSE,
'modules/system/system.messages.css' => FALSE,
'modules/system/system.theme.css' => FALSE,
'modules/user/user.css' => FALSE,
);
$css = array_diff_key($css, $exclude);
}
function boostrapdrupal_menu_tree(&$variables) {
return '<ul class="nav nav-pills nav-stacked">' . $variables['tree'] . '</ul>';
}
function boostrapdrupal_menu_tree__main_menu(&$variables) {
return '<ul class="nav navbar-nav pull-right-md">' . $variables['tree'] . '</ul>';
}
function boostrapdrupal_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
unset($element['#below']['#theme_wrappers']);
$sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
$element['#attributes']['class'][] = "dropdown";
$element['#title'] .= ' <span class="caret"></span>';
$element['#attributes']['class'][] = 'dropdown';
$element['#localized_options']['html'] = TRUE;
$element['#localized_options']['attributes']['data-target'] = '#';
$element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
$element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
}
$active_trail = array_search('active-trail',$element['#attributes']['class']);
if($active_trail)
$element['#attributes']['class'][$active_trail] = 'active';
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
function boostrapdrupal_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
$breadcrumb[] = drupal_get_title();
$output = '<ol class="breadcrumb">';
foreach($breadcrumb as $crumb) {
if(end($breadcrumb) !== $crumb)
$output .= "<li>$crumb</li>";
else
$output .= "<li class=\"active\">$crumb</li>";
}
$output .= '</ol>';
return $output;
}
}
function boostrapdrupal_status_messages($variables) {
$display = $variables['display'];
$output = '';
$status_heading = array(
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
);
foreach (drupal_get_messages($display) as $type => $messages) {
$conv_type = convert_status($type);
$output .= "<div class=\"alert $conv_type alert-dismissable\">\n";
$output .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= $messages[0];
}
$output .= "</div>\n";
}
return $output;
}
function convert_status($type) {
switch($type) {
case 'status':
return 'alert-success';
break;
case 'warning':
return 'alert-warning';
break;
case 'error':
return 'alert-danger';
break;
default:
return 'alert-info';
break;
}
}
function boostrapdrupal_menu_local_tasks(&$variables) {
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<h2 class="sr-only">' . t('Primary tabs') . '</h2>';
$variables['primary']['#prefix'] .= '<ul class="nav nav-tabs primary">';
$variables['primary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<h2 class="sr-only">' . t('Secondary tabs') . '</h2>';
$variables['secondary']['#prefix'] .= '<ul class="nav nav-tabs secondary">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['secondary']);
}
return $output;
}