Same name and namespace in other branches
  1. 4.6.x includes/bootstrap.inc \drupal_get_messages()
  2. 4.7.x includes/bootstrap.inc \drupal_get_messages()
  3. 5.x includes/bootstrap.inc \drupal_get_messages()
  4. 6.x includes/bootstrap.inc \drupal_get_messages()
  5. 8.9.x core/includes/bootstrap.inc \drupal_get_messages()

Returns all messages that have been set with drupal_set_message().

Parameters

string $type: (optional) Limit the messages returned by type. Defaults to NULL, meaning all types. These values are supported:

  • NULL
  • 'status'
  • 'warning'
  • 'error'

bool $clear_queue: (optional) If this is TRUE, the queue will be cleared of messages of the type specified in the $type parameter. Otherwise the queue will be left intact. Defaults to TRUE.

Return value

array A multidimensional array with keys corresponding to the set message types. The indexed array values of each contain the set messages for that type. The messages returned are limited to the type specified in the $type parameter. If there are no messages of the specified type, an empty array is returned.

See also

drupal_set_message()

theme_status_messages()

6 calls to drupal_get_messages()
DrupalTestCase::run in modules/simpletest/drupal_web_test_case.php
Run all tests in this class.
FileNameMungingTest::testMunging in modules/simpletest/tests/file.test
Create a file and munge/unmunge the name.
FormsElementsTableSelectFunctionalTest::formSubmitHelper in modules/simpletest/tests/form.test
Helper function for the option check test to submit a form while collecting errors.
FormsTestCase::testRequiredFields in modules/simpletest/tests/form.test
Check several empty values for required forms elements.
openid_authentication in modules/openid/openid.module
Authenticate a user or attempt registration.

... See full list

File

includes/bootstrap.inc, line 2165
Functions that need to be loaded on every Drupal request.

Code

function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
  if ($messages = drupal_set_message()) {
    if ($type) {
      if ($clear_queue) {
        unset($_SESSION['messages'][$type]);
      }
      if (isset($messages[$type])) {
        return array(
          $type => $messages[$type],
        );
      }
    }
    else {
      if ($clear_queue) {
        unset($_SESSION['messages']);
      }
      return $messages;
    }
  }
  return array();
}