4.6.x theme.inc theme_status_messages()
4.7.x theme.inc theme_status_messages()
5.x theme.inc theme_status_messages($display = NULL)
6.x theme.inc theme_status_messages($display = NULL)
7.x theme.inc theme_status_messages($variables)

Returns HTML for status and/or error 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.

Parameters

$variables: An associative array containing:

  • display: (optional) Set to 'status' or 'error' to display only messages of that type.

Related topics

5 theme calls to theme_status_messages()
ajax_prepare_response in includes/ajax.inc
Converts the return value of a page callback into an Ajax commands array.
file_ajax_upload in modules/file/file.module
Menu callback; Shared Ajax callback for file uploads and deletions.
hook_ajax_render_alter in modules/system/system.api.php
Alter the commands that are sent to the user through the Ajax framework.
template_preprocess_maintenance_page in includes/theme.inc
Process variables for maintenance-page.tpl.php.
template_process_page in includes/theme.inc
Process variables for page.tpl.php

File

includes/theme.inc, line 1673
The theme system, which controls the output of Drupal.

Code

function theme_status_messages($variables) {
  $display = $variables['display'];
  $output = '';

  $status_heading = 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 $type\">\n";
    if (!empty($status_heading[$type])) {
      $output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
    }
    if (count($messages) > 1) {
      $output .= " <ul>\n";
      foreach ($messages as $message) {
        $output .= '  <li>' . $message . "</li>\n";
      }
      $output .= " </ul>\n";
    }
    else {
      $output .= reset($messages);
    }
    $output .= "</div>\n";
  }
  return $output;
}

Comments

mikeytown2’s picture

template_process_page() calls theme('status_messages')

emcniece’s picture

Not sure if this is right, but...

Was getting an error message with plain old `print theme_status_messages();`:

Warning: Missing argument 1 for theme_status_messages(), called in /var/www/html/modules/php/php.module(80) : eval()'d code on line 4 and defined in theme_status_messages() (line 1492 of /var/www/html/includes/theme.inc).

Fixed by calling like so:

    global $variables;
    print theme_status_messages($variables);
roper.’s picture

You shouldn't call theme functions directly, pretty much ever...

Instead, just do print theme('status_messages'); which will look up the theme function in Drupal's registry, see if there's an override of it, and provide the default values for you as well.

blainelang’s picture

I was having an issue with the drupal messages and errors not appearing on the drupal commerce checkout page and solved it with the following code in the a hook_checkout_form_alter

$form['account']['#prefix'] = theme_status_messages(array('display' => ''));

Needed to pass in the array as I have it else was getting notice errors.

suvzz’s picture

errors set by form_set_error()

mchar’s picture

This is how I used theme() to print a message inside a block:
theme('status_messages', drupal_set_message(t('No searches yet! Be the first to search this site'), 'status'));