forked from makinacorpus/drupal-badm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.php
486 lines (438 loc) · 14.3 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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<?php
/**
* Forms alteration.
*/
require_once __DIR__ . '/templates/form/template.php';
/**
* Implements hook_preprocess_page().
*/
function badm_preprocess_page(&$page) {
// Force some JS inclusion.
$opts = ['preprocess' => true, 'every_page' => true];
$path = drupal_get_path('theme', 'badm');
drupal_add_js($path . '/bootstrap/js/alert.js', $opts);
drupal_add_js($path . '/bootstrap/js/button.js', $opts);
drupal_add_js($path . '/bootstrap/js/collapse.js', $opts);
drupal_add_js($path . '/bootstrap/js/dropdown.js', $opts);
drupal_add_js($path . '/bootstrap/js/modal.js', $opts);
drupal_add_js($path . '/bootstrap/js/tab.js', $opts);
drupal_add_js($path . '/bootstrap/js/tooltip.js', $opts);
drupal_add_js($path . '/bootstrap/js/popover.js', $opts);
}
/**
* Overrides theme_menu_local_task().
*/
function badm_menu_local_task($variables) {
$link = $variables['element']['#link'];
$link_text = $link['title'];
if (!empty($variables['element']['#active'])) {
$active = '<span class="sr-only">' . t('(active tab)') . '</span>';
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link_text = t('!local-task-title!active', ['!local-task-title' => $link['title'], '!active' => $active]);
}
return '<li role="presentation"' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";
}
/**
* Overrides theme_menu_local_tasks().
*/
function badm_menu_local_tasks(&$variables) {
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<ul class="nav nav-tabs">';
$variables['primary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<ul class="nav nav-tabs">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['secondary']);
}
return $output;
}
/**
* Overrides theme_menu_local_action().
*/
function badm_menu_local_action($variables) {
$link = $variables['element']['#link'];
// $output = '<li role="presentation">';
if (!empty($link['localized_options']['html'])) {
$title = '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>' . $link['title'];
} else {
$title = '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>' . check_plain($link['title']);
}
$link['localized_options']['html'] = true;
if (isset($link['href'])) {
$link['localized_options']['attributes']['class'][] = 'btn';
$link['localized_options']['attributes']['class'][] = 'btn-info';
$output .= l($title, $link['href'], $link['localized_options']);
} else {
$output .= $title;
}
// $output .= "</li>";
return $output;
}
/**
* Overrides theme_breadcrumb().
*/
function badm_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
$output = '<h2 class="sr-only">' . t('You are here') . '</h2>';
if (!empty($breadcrumb)) {
$links = '<li>' . implode('</li><li>', $breadcrumb) . '</li>';
} else {
$links = '';
}
$output .= '<ol class="breadcrumb">' . $links . '<li class="active">' . drupal_get_title() . '</li></ol>';
return $output;
}
}
/**
* Overrides theme_status_messages().
*/
function badm_status_messages($variables) {
$display = $variables['display'];
$output = '';
foreach (drupal_get_messages($display) as $type => $messages) {
switch ($type) {
case 'error':
$class = 'alert-danger alert-dismissible';
break;
case 'warning':
$class = 'alert-warning alert-dismissible';
break;
default:
$class = 'alert-info alert-dismissible';
break;
}
foreach ($messages as $message) {
$output .= '<div class="alert ' . $class . '" role="alert">';
$output .= $message;
$output .= '<button type="button" class="close" data-dismiss="alert" aria-label="' . t("Close") . '"><span aria-hidden="true">×</span></button>';
$output .= '</div>';
}
}
return $output;
}
/**
* Overrides theme_admin_block().
*/
function badm_admin_block($variables) {
$block = $variables['block'];
$output = '';
if (empty($block['show'])) {
return $output;
}
$output = '<div class="panel panel-default">';
if (!empty($block['title'])) {
$output .= '<div class="panel-heading"><h3 class="panel-title">' . $block['title'] . '</h3></div>';
}
$output .= '<div class="panel-body">';
if (!empty($block['content'])) {
$output .= $block['content'];
}
else {
$output .= '<p class="description">' . $block['description'] . '</p>';
}
return $output . '</div></div>';
}
/**
* Overrides theme_admin_block_content().
*/
function badm_admin_block_content($variables) {
$content = $variables['content'];
$output = '';
if (!empty($content)) {
$compact = system_admin_compact_mode();
$output .= '<dl>';
foreach ($content as $item) {
$output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
if (!$compact && isset($item['description'])) {
$output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
}
}
$output .= '</dl>';
}
return $output;
}
/**
* Overrides theme_admin_page().
*/
function badm_admin_page($variables) {
$blocks = $variables['blocks'];
$stripe = 0;
$output = '';
$container = [];
foreach ($blocks as $block) {
if ($block_output = theme('admin_block', ['block' => $block])) {
if (empty($block['position'])) {
// perform automatic striping.
$block['position'] = ++$stripe % 2 ? 'left' : 'right';
}
if (!isset($container[$block['position']])) {
$container[$block['position']] = '';
}
$container[$block['position']] .= $block_output;
}
}
//$output .= theme('system_compact_link');
foreach ($container as $data) {
$output .= '<div class="col-md-6">';
$output .= $data;
$output .= '</div>';
}
return '<div class="row">' . $output . '</div>';
}
/**
* Overrides theme_system_admin_index().
*/
function badm_system_admin_index($variables) {
$menu_items = $variables['menu_items'];
$container = ['left' => '', 'right' => ''];
$flip = ['left' => 'right', 'right' => 'left'];
$position = 'left';
// Iterate over all modules.
foreach ($menu_items as $module => $block) {
list($description, $items) = $block;
// Output links.
if (count($items)) {
$block = [
'title' => $module,
'content' => theme('admin_block_content', ['content' => $items]),
'description' => t($description),
'show' => true,
];
if ($block_output = theme('admin_block', ['block' => $block])) {
if (!isset($block['position'])) {
// Perform automatic striping.
$block['position'] = $position;
$position = $flip[$position];
}
$container[$block['position']] .= $block_output;
}
}
}
$output = theme('system_compact_link');
foreach ($container as $id => $data) {
$output .= '<div class="' . $id . ' clearfix">';
$output .= $data;
$output .= '</div>';
}
return $output;
}
/**
* Overrides theme_status_report().
*/
function badm_status_report($variables) {
$requirements = $variables['requirements'];
$severities = [
REQUIREMENT_INFO => [
'title' => t('Info'),
'class' => 'info',
],
REQUIREMENT_OK => [
'title' => t('OK'),
'class' => 'success',
],
REQUIREMENT_WARNING => [
'title' => t('Warning'),
'class' => 'warning',
],
REQUIREMENT_ERROR => [
'title' => t('Error'),
'class' => 'danger',
],
];
$output = '<table class="table table-condensed">';
foreach ($requirements as $requirement) {
if (empty($requirement['#type'])) {
$severity = $severities[isset($requirement['severity']) ? (int) $requirement['severity'] : REQUIREMENT_OK];
// Output table row(s)
if (!empty($requirement['description'])) {
$output .= '<tr class="' . $severity['class'] . ' merge-down"><td class="status-title">' . $requirement['title'] . '</td><td class="status-value">' . $requirement['value'] . '</td></tr>';
$output .= '<tr class="' . $severity['class'] . ' merge-up"><td colspan="2" class="status-description">' . $requirement['description'] . '</td></tr>';
}
else {
$output .= '<tr class="' . $severity['class'] . '"><td class="status-title">' . $requirement['title'] . '</td><td class="status-value">' . $requirement['value'] . '</td></tr>';
}
}
}
$output .= '</table>';
return $output;
}
/**
* Overrides theme_table().
*/
function badm_table($variables) {
$header = $variables['header'];
$rows = $variables['rows'];
$attributes = $variables['attributes'];
$caption = $variables['caption'];
$colgroups = $variables['colgroups'];
$empty = $variables['empty'];
$attributes['class'][] = 'table';
$attributes['class'][] = 'table-striped';
$output = '<table' . drupal_attributes($attributes) . ">\n";
if (isset($caption)) {
$output .= '<caption>' . $caption . "</caption>\n";
}
// Format the table columns:
if (count($colgroups)) {
foreach ($colgroups as $colgroup) {
$attributes = array();
// Check if we're dealing with a simple or complex column
if (isset($colgroup['data'])) {
foreach ($colgroup as $key => $value) {
if ($key == 'data') {
$cols = $value;
} else {
$attributes[$key] = $value;
}
}
} else {
$cols = $colgroup;
}
// Build colgroup
if (is_array($cols) && count($cols)) {
$output .= ' <colgroup' . drupal_attributes($attributes) . '>';
$i = 0;
foreach ($cols as $col) {
$output .= ' <col' . drupal_attributes($col) . ' />';
}
$output .= " </colgroup>\n";
} else {
$output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
}
}
}
// Add the 'empty' row message if available.
if (!count($rows) && $empty) {
$header_count = 0;
foreach ($header as $header_cell) {
if (is_array($header_cell)) {
$header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
} else {
$header_count++;
}
}
$rows[] = array(array('data' => $empty, 'colspan' => $header_count, 'class' => array('empty', 'message')));
}
// Format the table header:
if (count($header)) {
$ts = tablesort_init($header);
// HTML requires that the thead tag has tr tags in it followed by tbody
// tags. Using ternary operator to check and see if we have any rows.
$output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
foreach ($header as $cell) {
$cell = tablesort_header($cell, $header, $ts);
$output .= _theme_table_cell($cell, TRUE);
}
// Using ternary operator to close the tags based on whether or not there are rows
$output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
} else {
$ts = array();
}
// Format the table rows:
if (count($rows)) {
$output .= "<tbody>\n";
foreach ($rows as $row) {
$attributes = array();
// Check if we're dealing with a simple or complex row
if (isset($row['data'])) {
foreach ($row as $key => $value) {
if ($key == 'data') {
$cells = $value;
} else {
$attributes[$key] = $value;
}
}
} else {
$cells = $row;
}
if (count($cells)) {
// Build row
$output .= ' <tr' . drupal_attributes($attributes) . '>';
$i = 0;
foreach ($cells as $cell) {
$cell = tablesort_cell($cell, $header, $ts, $i++);
$output .= _theme_table_cell($cell);
}
$output .= " </tr>\n";
}
}
$output .= "</tbody>\n";
}
$output .= "</table>\n";
return $output;
}
/**
* Overrides theme_links().
*/
function badm_links__toolbar_menu(&$variables) {
global $language_url;
$links = $variables['links'];
$output = '';
$title = t("Administration");
if (!empty($links)) {
$output = <<<EOT
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
{$title} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
EOT;
foreach ($links as $link) {
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page())) && (empty($link['language']) || $link['language']->language == $language_url->language)) {
$output .= '<li class="active">';
} else {
$output .= '<li>';
}
if (isset($link['href'])) {
// Title we got here is wrong.
$link['title'] = str_replace(['<span class="element-invisible">'], ['<span class="sr-only">'], $link['title']);
$output .= l($link['title'], $link['href'], $link);
}
$output .= '</li>';
}
$output .= '</ul></li></ul>';
}
return $output;
}
/**
* Overrides theme_links().
*/
function badm_links__toolbar_user(&$variables) {
global $language_url;
$links = $variables['links'];
$output = '';
$title = t("Account");
if (!empty($links)) {
$output = <<<EOT
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
{$title} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
EOT;
foreach ($links as $link) {
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page())) && (empty($link['language']) || $link['language']->language == $language_url->language)) {
$output .= '<li class="active">';
} else {
$output .= '<li>';
}
if (isset($link['href'])) {
// Title we got here is wrong.
$link['title'] = str_replace(['<span class="element-invisible">'], ['<span class="sr-only">'], $link['title']);
$output .= l($link['title'], $link['href'], $link);
}
$output .= '</li>';
}
$output .= '</ul></li></ul>';
}
return $output;
}