diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 6286f65..06e589a 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1601,44 +1601,22 @@ function template_preprocess_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) May have a value of 'status' or 'error' when only + * displaying messages of that specific type. */ -function theme_status_messages($variables) { - $display = $variables['display']; - $output = ''; - - $status_heading = array( +function template_preprocess_status_messages(&$variables) { + $variables['message_list'] = 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; } /** @@ -3088,6 +3066,7 @@ function drupal_common_theme() { ), 'status_messages' => array( 'variables' => array('display' => NULL), + 'template' => 'status-messages', ), 'links' => array( 'variables' => array('links' => array(), 'attributes' => array('class' => array('links')), 'heading' => 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..9228d3b --- /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: + * - 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. + * + * @see template_preprocess() + * @see template_preprocess_status_messages() + * + * @ingroup themeable + */ +#} +{% for type, messages in message_list %} +
+ {% if status_headings[type] %} +

{{ status_headings[type] }}

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