Issue #1939082 by shanethehat, larowlan, jenlampton, Cottser, LewisNyman, duellj, Mark Carver, joelpittet: Convert theme_status_messages() to Twig.
parent
5e9ac4dd2d
commit
ce46702f85
|
@ -1572,44 +1572,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 .= "<div class=\"messages messages--$type\">\n";
|
||||
if (!empty($status_heading[$type])) {
|
||||
$output .= '<h2 class="visually-hidden">' . $status_heading[$type] . "</h2>\n";
|
||||
}
|
||||
if (count($messages) > 1) {
|
||||
$output .= " <ul class=\"messages__list\">\n";
|
||||
foreach ($messages as $message) {
|
||||
$output .= ' <li class="messages__item">' . $message . "</li>\n";
|
||||
}
|
||||
$output .= " </ul>\n";
|
||||
}
|
||||
else {
|
||||
$output .= $messages[0];
|
||||
}
|
||||
$output .= "</div>\n";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3032,6 +3010,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()),
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
{#
|
||||
/**
|
||||
* @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_status_messages()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% for type, messages in message_list %}
|
||||
<div class="messages messages--{{ type }}">
|
||||
{% if status_headings[type] %}
|
||||
<h2 class="visually-hidden">{{ status_headings[type] }}</h2>
|
||||
{% endif %}
|
||||
{% if messages|length > 1 %}
|
||||
<ul class="messages__list">
|
||||
{% for message in messages %}
|
||||
<li class="messages__item">{{ message }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{{ messages.0 }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
Loading…
Reference in New Issue