You are here

status-messages.html.twig in Drupal 9

Theme override for status messages.

Displays status, error, and warning messages, grouped by type.

An invisible heading identifies the messages for assistive technology. Sighted users see a colored box. See https://www.w3.org/TR/WCAG-TECHS/H69.html for info.

Add an ARIA label to the contentinfo area so that assistive technology user agents will better describe this landmark.

Available variables:

  • message_list: List of messages to be displayed, grouped by type.
  • status_headings: List of all status types.
  • attributes: HTML attributes for the element, including:
    • class: HTML classes.

File

core/themes/olivero/templates/misc/status-messages.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for status messages.
  5. *
  6. * Displays status, error, and warning messages, grouped by type.
  7. *
  8. * An invisible heading identifies the messages for assistive technology.
  9. * Sighted users see a colored box. See
  10. * https://www.w3.org/TR/WCAG-TECHS/H69.html for info.
  11. *
  12. * Add an ARIA label to the contentinfo area so that assistive technology
  13. * user agents will better describe this landmark.
  14. *
  15. * Available variables:
  16. * - message_list: List of messages to be displayed, grouped by type.
  17. * - status_headings: List of all status types.
  18. * - attributes: HTML attributes for the element, including:
  19. * - class: HTML classes.
  20. */
  21. #}
  22. {{ attach_library('olivero/messages') }}
  23. <div data-drupal-messages class="messages-list">
  24. {% for type, messages in message_list %}
  25. {%
  26. set classes = [
  27. 'messages-list__item',
  28. 'messages',
  29. 'messages--' ~ type,
  30. ]
  31. %}
  32. <div{{ attributes
  33. .addClass(classes)
  34. .setAttribute('data-drupal-selector', 'messages')
  35. .setAttribute('role', 'contentinfo')
  36. .setAttribute('aria-label', status_headings[type])
  37. }}>
  38. <div class="messages__container" data-drupal-selector="messages-container"{% if type == 'error' %} role="alert"{% endif %}>
  39. {% if status_headings[type] %}
  40. <div class="messages__header">
  41. <h2 class="visually-hidden">{{ status_headings[type] }}</h2>
  42. <div class="messages__icon">
  43. {% if type == 'error' %}
  44. {% include "@olivero/../images/error.svg" %}
  45. {% elseif type == 'warning' %}
  46. {% include "@olivero/../images/warning.svg" %}
  47. {% elseif type == 'status' %}
  48. {% include "@olivero/../images/status.svg" %}
  49. {% elseif type == 'info' %}
  50. {% include "@olivero/../images/info.svg" %}
  51. {% endif %}
  52. </div>
  53. </div>
  54. {% endif %}
  55. <div class="messages__content">
  56. {% if messages|length > 1 %}
  57. <ul class="messages__list">
  58. {% for message in messages %}
  59. <li class="messages__item">{{ message }}</li>
  60. {% endfor %}
  61. </ul>
  62. {% else %}
  63. {{ messages|first }}
  64. {% endif %}
  65. </div>
  66. </div>
  67. </div>
  68. {# Remove type specific classes. #}
  69. {% set attributes = attributes.removeClass(classes) %}
  70. {% endfor %}
  71. </div>