8.5.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8.0.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8.1.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8.2.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8.3.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8.4.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
8.6.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
4.6.x bootstrap.inc drupal_get_messages()
4.7.x bootstrap.inc drupal_get_messages()
5.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
6.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)
7.x bootstrap.inc drupal_get_messages($type = NULL, $clear_queue = TRUE)

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 An associative, nested array of messages grouped by message type, with the top-level keys as the message type. The messages returned are limited to the type specified in the $type parameter, if any. If there are no messages of the specified type, an empty array is returned. See drupal_set_message() for the array structure of individual messages.

See also

drupal_set_message()

status-messages.html.twig

10 calls to drupal_get_messages()
BlockRebuildTest::testRebuildInvalidBlocks in core/modules/block/tests/src/Kernel/BlockRebuildTest.php
@covers ::block_rebuild
BlockRebuildTest::testRebuildNoBlocks in core/modules/block/tests/src/Kernel/BlockRebuildTest.php
@covers ::block_rebuild
BlockRebuildTest::testRebuildNoInvalidBlocks in core/modules/block/tests/src/Kernel/BlockRebuildTest.php
@covers ::block_rebuild
DrupalSetMessageTest::testDrupalSetMessage in core/tests/Drupal/KernelTests/Core/Common/DrupalSetMessageTest.php
The basic functionality of drupal_set_message().
ElementsTableSelectTest::formSubmitHelper in core/modules/system/src/Tests/Form/ElementsTableSelectTest.php
Helper function for the option check test to submit a form while collecting errors.

... See full list

File

core/includes/bootstrap.inc, line 511
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 [
          $type => $messages[$type],
        ];
      }
    }
    else {
      if ($clear_queue) {
        unset($_SESSION['messages']);
      }
      return $messages;
    }
  }
  return [];
}