diff --git a/core/lib/Drupal/Core/Messenger/LegacyMessenger.php b/core/lib/Drupal/Core/Messenger/LegacyMessenger.php index 69c229286e..71cfaec09f 100644 --- a/core/lib/Drupal/Core/Messenger/LegacyMessenger.php +++ b/core/lib/Drupal/Core/Messenger/LegacyMessenger.php @@ -70,6 +70,54 @@ public function deleteByType($type) { } /** + * Sets a message to display to the user. + * + * Messages are stored in a session variable and displayed in the page template + * via the $messages theme variable. + * + * Example usage: + * @code + * drupal_set_message(t('An error occurred and processing did not complete.'), 'error'); + * @endcode + * + * @param string|\Drupal\Component\Render\MarkupInterface $message + * (optional) The translated message to be displayed to the user. For + * consistency with other messages, it should begin with a capital letter and + * end with a period. + * @param string $type + * (optional) The message's type. Defaults to 'status'. These values are + * supported: + * - 'status' + * - 'warning' + * - 'error' + * @param bool $repeat + * (optional) If this is FALSE and the message is already set, then the + * message won't be repeated. Defaults to FALSE. + * + * @return array|null + * A multidimensional array with keys corresponding to the set message types. + * The indexed array values of each contain the set messages for that type, + * and each message is an associative array with the following format: + * - safe: Boolean indicating whether the message string has been marked as + * safe. Non-safe strings will be escaped automatically. + * - message: The message string. + * So, the following is an example of the full return array structure: + * @code + * array( + * 'status' => array( + * array( + * 'safe' => TRUE, + * 'message' => 'A safe markup string.', + * ), + * array( + * 'safe' => FALSE, + * 'message' => "$arbitrary_user_input to escape.", + * ), + * ), + * ); + * @endcode + * If there are no messages set, the function returns NULL. + * * @internal */ private function setMessage($message = NULL, $type = 'status', $repeat = FALSE) { @@ -123,9 +171,6 @@ private function setMessage($message = NULL, $type = 'status', $repeat = FALSE) * @see status-messages.html.twig * * @internal - * @deprecated Deprecated as of Drupal 8.5. - * Use \Drupal::service('messenger')->getMessages() or - * \Drupal::service('messenger')->getMessagesByType() instead. */ private function getMessages($type = NULL, $clear_queue = TRUE) { if ($messages = $this->setMessage()) {