public static function StatusMessages::renderMessages

public static StatusMessages::renderMessages($type)

#lazy_builder callback; replaces placeholder with messages.

Parameters

string|null $type: Limit the messages returned by type. Defaults to NULL, meaning all types. Passed on to drupal_get_messages(). These values are supported:

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

Return value

array A renderable array containing the messages.

See also

drupal_get_messages()

File

core/lib/Drupal/Core/Render/Element/StatusMessages.php, line 72

Class

StatusMessages
Provides a messages element.

Namespace

Drupal\Core\Render\Element

Code

public static function renderMessages($type) {
  // Render the messages.
  return [
    '#theme' => 'status_messages',
    // @todo Improve when https://www.drupal.org/node/2278383 lands.
    '#message_list' => drupal_get_messages($type),
    '#status_headings' => [
      'status' => t('Status message'),
      'error' => t('Error message'),
      'warning' => t('Warning message'),
    ],
  ];
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!StatusMessages.php/function/StatusMessages::renderMessages/8.1.x