function StatusMessages::renderMessages
#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\Core\Messenger\Messenger::deleteByType(). These values are supported:
- NULL
- 'status'
- 'warning'
- 'error'
Return value
array A renderable array containing the messages.
See also
\Drupal\Core\Messenger\Messenger::deleteByType()
File
- 
              core/lib/ Drupal/ Core/ Render/ Element/ StatusMessages.php, line 88 
Class
- StatusMessages
- Provides a messages element.
Namespace
Drupal\Core\Render\ElementCode
public static function renderMessages($type = NULL) {
  $render = [];
  if (isset($type)) {
    $messages = [
      $type => \Drupal::messenger()->deleteByType($type),
    ];
  }
  else {
    $messages = \Drupal::messenger()->deleteAll();
  }
  if ($messages) {
    // Render the messages.
    $render = [
      '#theme' => 'status_messages',
      '#message_list' => $messages,
      '#status_headings' => [
        'status' => t('Status message'),
        'error' => t('Error message'),
        'warning' => t('Warning message'),
      ],
    ];
  }
  return $render;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
