file status-messages.func.php

Stub file for bootstrap_status_messages().

  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(array $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. // Retrieve messages.
  46. $message_list = drupal_get_messages($display);
  47. // Allow the disabled_messages module to filter the messages, if enabled.
  48. if (module_exists('disable_messages') && variable_get('disable_messages_enable', '1')) {
  49. $message_list = disable_messages_apply_filters($message_list);
  50. }
  51. foreach ($message_list as $type => $messages) {
  52. $class = (isset($status_class[$type])) ? ' alert-' . $status_class[$type] : '';
  53. $output .= "<div class=\"alert alert-block alert-dismissible$class messages $type\">\n";
  54. $output .= " <a class=\"close\" data-dismiss=\"alert\" href=\"#\">&times;</a>\n";
  55. if (!empty($status_heading[$type])) {
  56. $output .= '<h4 class="element-invisible">' . filter_xss_admin($status_heading[$type]) . "</h4>\n";
  57. }
  58. if (count($messages) > 1) {
  59. $output .= " <ul>\n";
  60. foreach ($messages as $message) {
  61. $output .= ' <li>' . filter_xss_admin($message) . "</li>\n";
  62. }
  63. $output .= " </ul>\n";
  64. }
  65. else {
  66. $output .= filter_xss_admin(reset($messages));
  67. }
  68. $output .= "</div>\n";
  69. }
  70. return $output;
  71. }

Functions

Name Description
bootstrap_status_messages Returns HTML for status and/or error messages, grouped by type.