diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 9a4f2ee..8c4cf23 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1640,44 +1640,22 @@ function theme_datetime($variables) { } /** - * Returns HTML for status and/or error messages, grouped by type. + * Prepares variables for status message templates. * - * 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. + * Default template: status-messages.html.twig. * - * @param $variables + * @param array $variables * An associative array containing: - * - display: (optional) Set to 'status' or 'error' to display only messages - * of that type. + * - display: (optional) Set to e.g. 'status' or 'error' to display only + * messages of that type. */ -function theme_status_messages($variables) { - $display = $variables['display']; - $output = ''; - - $status_heading = array( +function template_preprocess_status_messages(&$variables) { + $variables['messages_display'] = drupal_get_messages($variables['display']); + $variables['status_headings'] = array( 'status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'), ); - foreach (drupal_get_messages($display) as $type => $messages) { - $output .= "
\n"; - if (!empty($status_heading[$type])) { - $output .= '

' . $status_heading[$type] . "

\n"; - } - if (count($messages) > 1) { - $output .= " \n"; - } - else { - $output .= $messages[0]; - } - $output .= "
\n"; - } - return $output; } /** @@ -3148,6 +3126,7 @@ function drupal_common_theme() { ), 'status_messages' => array( 'variables' => array('display' => NULL), + 'template' => 'status-messages', ), 'link' => array( 'variables' => array('text' => NULL, 'path' => NULL, 'options' => array()), diff --git a/core/modules/system/templates/status-messages.html.twig b/core/modules/system/templates/status-messages.html.twig new file mode 100644 index 0000000..bd0ad0c --- /dev/null +++ b/core/modules/system/templates/status-messages.html.twig @@ -0,0 +1,39 @@ +{# +/** + * @file + * Default theme implementation 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. + * + * Available variables: + * - messages_display: List of messages to be displayed, grouped by type. + * - status_headings: List of all status types. + * - display: (optional) Has a value of e.g. 'status' or 'error' when only + * displaying messages of that type. + * + * @see template_preprocess() + * @see template_preprocess_status_messages() + * + * @ingroup themeable + */ +#} +{% for type, messages in messages_display %} +
+ {% if status_headings[type] %} +

{{ status_headings[type] }}

+ {% endif %} + {% if messages|length > 1 %} + + {% else %} + {{ messages.0 }} + {% endif %} +
+{% endfor %}