root / drupal7 / sites / all / themes / bootstrap / templates / system / status-messages.func.php @ 749b8a23
1 | 87dbc3bf | Benjamin Luce | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * @file
|
||
4 | caf16a48 | Assos Assos | * Stub file for bootstrap_status_messages().
|
5 | 87dbc3bf | Benjamin Luce | */
|
6 | |||
7 | /**
|
||
8 | caf16a48 | Assos Assos | * 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 | 87dbc3bf | Benjamin Luce | */
|
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 | foreach (drupal_get_messages($display) as $type => $messages) { |
||
50 | $class = (isset($status_class[$type])) ? ' alert-' . $status_class[$type] : ''; |
||
51 | caf16a48 | Assos Assos | $output .= "<div class=\"alert alert-block$class messages $type\">\n"; |
52 | 87dbc3bf | Benjamin Luce | $output .= " <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>\n"; |
53 | |||
54 | if (!empty($status_heading[$type])) { |
||
55 | $output .= '<h4 class="element-invisible">' . $status_heading[$type] . "</h4>\n"; |
||
56 | } |
||
57 | |||
58 | if (count($messages) > 1) { |
||
59 | $output .= " <ul>\n"; |
||
60 | foreach ($messages as $message) { |
||
61 | $output .= ' <li>' . $message . "</li>\n"; |
||
62 | } |
||
63 | $output .= " </ul>\n"; |
||
64 | } |
||
65 | else {
|
||
66 | $output .= $messages[0]; |
||
67 | } |
||
68 | |||
69 | $output .= "</div>\n"; |
||
70 | } |
||
71 | return $output; |
||
72 | } |