root / drupal7 / sites / all / themes / bootstrap / templates / system / status-messages.func.php @ 1f623f01
1 |
<?php
|
---|---|
2 |
/**
|
3 |
* @file
|
4 |
* Stub file for bootstrap_status_messages().
|
5 |
*/
|
6 |
|
7 |
/**
|
8 |
* Returns HTML for status and/or error messages, grouped by type.
|
9 |
*
|
10 |
* An invisible heading identifies the messages for assistive technology.
|
11 |
* Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html
|
12 |
* for info.
|
13 |
*
|
14 |
* @param array $variables
|
15 |
* An associative array containing:
|
16 |
* - display: (optional) Set to 'status' or 'error' to display only messages
|
17 |
* of that type.
|
18 |
*
|
19 |
* @return string
|
20 |
* The constructed HTML.
|
21 |
*
|
22 |
* @see theme_status_messages()
|
23 |
*
|
24 |
* @ingroup theme_functions
|
25 |
*/
|
26 |
function bootstrap_status_messages($variables) { |
27 |
$display = $variables['display']; |
28 |
$output = ''; |
29 |
|
30 |
$status_heading = array( |
31 |
'status' => t('Status message'), |
32 |
'error' => t('Error message'), |
33 |
'warning' => t('Warning message'), |
34 |
'info' => t('Informative message'), |
35 |
); |
36 |
|
37 |
// Map Drupal message types to their corresponding Bootstrap classes.
|
38 |
// @see http://twitter.github.com/bootstrap/components.html#alerts
|
39 |
$status_class = array( |
40 |
'status' => 'success', |
41 |
'error' => 'danger', |
42 |
'warning' => 'warning', |
43 |
// Not supported, but in theory a module could send any type of message.
|
44 |
// @see drupal_set_message()
|
45 |
// @see theme_status_messages()
|
46 |
'info' => 'info', |
47 |
); |
48 |
|
49 |
// Retrieve messages.
|
50 |
$message_list = drupal_get_messages($display); |
51 |
|
52 |
// Allow the disabled_messages module to filter the messages, if enabled.
|
53 |
if (module_exists('disable_messages') && variable_get('disable_messages_enable', '1')) { |
54 |
$message_list = disable_messages_apply_filters($message_list); |
55 |
} |
56 |
|
57 |
foreach ($message_list as $type => $messages) { |
58 |
$class = (isset($status_class[$type])) ? ' alert-' . $status_class[$type] : ''; |
59 |
$output .= "<div class=\"alert alert-block$class messages $type\">\n"; |
60 |
$output .= " <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>\n"; |
61 |
|
62 |
if (!empty($status_heading[$type])) { |
63 |
$output .= '<h4 class="element-invisible">' . _bootstrap_filter_xss($status_heading[$type]) . "</h4>\n"; |
64 |
} |
65 |
|
66 |
if (count($messages) > 1) { |
67 |
$output .= " <ul>\n"; |
68 |
foreach ($messages as $message) { |
69 |
$output .= ' <li>' . _bootstrap_filter_xss($message) . "</li>\n"; |
70 |
} |
71 |
$output .= " </ul>\n"; |
72 |
} |
73 |
else {
|
74 |
$output .= $messages[0]; |
75 |
} |
76 |
|
77 |
$output .= "</div>\n"; |
78 |
} |
79 |
return $output; |
80 |
} |