Community Documentation

drupal_get_messages

5 bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
6 bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
7 bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8 bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)

Returns all messages that have been set.

Parameters

$type: (optional) Only return messages of this type.

$clear_queue: (optional) Set to FALSE if you do not want to clear the messages queue

Return value

An associative array, the key is the message type, the value an array of messages. If the $type parameter is passed, you get only that type, or an empty array if there are no such messages. If $type is not passed, all message types are returned, or an empty array if none exist.

▾ 6 functions call 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.
theme_status_messages in includes/theme.inc
Returns HTML for status and/or error messages, grouped by type.

File

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

Code

<?php
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();
}
?>
Login or register to post comments