Project

General

Profile

Paste
Download (2.34 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / themes / bootstrap / templates / system / status-messages.func.php @ 1f623f01

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 4eeb3b46 Assos Assos
  // 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 87dbc3bf Benjamin Luce
    $class = (isset($status_class[$type])) ? ' alert-' . $status_class[$type] : '';
59 caf16a48 Assos Assos
    $output .= "<div class=\"alert alert-block$class messages $type\">\n";
60 87dbc3bf Benjamin Luce
    $output .= "  <a class=\"close\" data-dismiss=\"alert\" href=\"#\">&times;</a>\n";
61
62
    if (!empty($status_heading[$type])) {
63 1f623f01 Assos Assos
      $output .= '<h4 class="element-invisible">' . _bootstrap_filter_xss($status_heading[$type]) . "</h4>\n";
64 87dbc3bf Benjamin Luce
    }
65
66
    if (count($messages) > 1) {
67
      $output .= " <ul>\n";
68
      foreach ($messages as $message) {
69 1f623f01 Assos Assos
        $output .= '  <li>' . _bootstrap_filter_xss($message) . "</li>\n";
70 87dbc3bf Benjamin Luce
      }
71
      $output .= " </ul>\n";
72
    }
73
    else {
74
      $output .= $messages[0];
75
    }
76
77
    $output .= "</div>\n";
78
  }
79
  return $output;
80
}