status-messages.func.php 2.0 KB

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