X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FRender%2FElement%2FStatusMessages.php;h=a5a28429812f4a0152c834071f1171366499bd1d;hb=4f1b9b4ab48a8498afac9e2213a02a23ccf4a06c;hp=d16c245a1d819228100b5e36367af73d69fad126;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Render/Element/StatusMessages.php b/web/core/lib/Drupal/Core/Render/Element/StatusMessages.php index d16c245a1..a5a284298 100644 --- a/web/core/lib/Drupal/Core/Render/Element/StatusMessages.php +++ b/web/core/lib/Drupal/Core/Render/Element/StatusMessages.php @@ -5,7 +5,7 @@ namespace Drupal\Core\Render\Element; /** * Provides a messages element. * - * Used to display results of drupal_set_message() calls. + * Used to display results of \Drupal::messenger()->addMessage() calls. * * Usage example: * @code @@ -61,7 +61,8 @@ class StatusMessages extends RenderElement { * * @param 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: + * Passed on to \Drupal\Core\Messenger\Messenger::deleteByType(). These + * values are supported: * - NULL * - 'status' * - 'warning' @@ -70,20 +71,30 @@ class StatusMessages extends RenderElement { * @return array * A renderable array containing the messages. * - * @see drupal_get_messages() + * @see \Drupal\Core\Messenger\Messenger::deleteByType() */ - 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'), - ], - ]; + public static function renderMessages($type = NULL) { + $render = []; + if (isset($type)) { + $messages = \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; } }