SU-SWS/stanford_profile

View on GitHub
themes/stanford_basic/templates/core/status-messages.html.twig

Summary

Maintainability
Test Coverage
{#
/**
 * @file
 * 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 http://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.
 * - display: (optional) May have a value of 'status' or 'error' when only
 *   displaying messages of that specific type.
 * - attributes: HTML attributes for the element, including:
 *   - class: HTML classes.
 *
 * @see template_preprocess_status_messages()
 */
#}

{# Template Paths #}
{%- if template_alert is empty -%}
  {% set template_alert = "@decanter/components/alert/alert.twig" %}
{%- endif -%}
{# End Template Paths. #}

{% for type, messages in message_list %}
  {% set attributes = create_attribute() %}
  {% set attributes = attributes.setAttribute('role', 'alert') %}

  {% if type == "status" %}
    {% set attributes = attributes.addClass('su-alert--info') %}
  {% else %}
    {% set attributes = attributes.addClass('su-alert--' ~ type) %}
  {% endif %}

  {% set light_text = ['status', 'error', 'success'] %}
  {% if type in light_text %}
    {% set attributes = attributes.addClass("su-alert--text-light") %}
  {% endif %}

  {% set modifier_class = attributes.class %}
  {% set attributes = attributes|without('class') %}

  {# Default Icon for Alerts. #}
  {%- set fa_class = "su-fas fa-bell" -%}
  {# Icon for error style. #}
  {%- if 'su-alert--error' in modifier_class -%}
    {%- set fa_class = "su-fas fa-exclamation-triangle" -%}
  {%- endif -%}
  {# Icon for success style. #}
  {%- if 'su-alert--success' in modifier_class -%}
    {%- set fa_class = "su-fas fa-check-circle" -%}
  {%- endif -%}
  {# Icon for warning style. #}
  {%- if 'su-alert--warning' in modifier_class -%}
    {%- set fa_class = "su-fas fa-exclamation-circle" -%}
  {%- endif -%}
  {# Icon for info style. #}
  {%- if 'su-alert--info' in modifier_class -%}
    {%- set fa_class = "su-fas fa-info-circle" -%}
  {%- endif -%}

  {# Create the HTML for the Alert Icon #}
  {% if alert_icon|render|striptags("<drupal-placeholder>") is empty %}
    {%- set alert_icon -%}
      <i class="{{ fa_class }}"></i>
    {%- endset -%}
  {% endif %}

  {# Good for everyone. #}
  {% if status_headings[type] %}
    <h2 class="visually-hidden">{{ status_headings[type] }}</h2>
  {% endif %}

  {% for message in messages %}
    {% set data = {
      'modifier_class': modifier_class,
      'attributes': attributes,
      'alert_label': type,
      'alert_text': message,
      'alert_icon': alert_icon,
      'alert_dismiss': true
      }
    %}
    {% include template_alert with data only %}
  {% endfor %}
{% endfor %}