summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-09-16 04:44:24 (GMT)
committerwebchick2013-09-16 04:44:24 (GMT)
commitce46702f85d15a160db2a737a28094039f827195 (patch)
tree686ca90681060f05ed9056fcfe40b8573319d7d9
parent5e9ac4dd2db45632aff33dff0dc50805e2e72419 (diff)
Issue #1939082 by shanethehat, larowlan, jenlampton, Cottser, LewisNyman, duellj, Mark Carver, joelpittet: Convert theme_status_messages() to Twig.
-rw-r--r--core/includes/theme.inc39
-rw-r--r--core/modules/system/templates/status-messages.html.twig38
2 files changed, 47 insertions, 30 deletions
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 6c240c7..d583eb7 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -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()),
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..aa17bf5
--- /dev/null
+++ b/core/modules/system/templates/status-messages.html.twig
@@ -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 %}