Issue #3094903 by kim.pepper, Dinesh18: Remove deprecated drupal_get_message() drupal_set_message() from bootstrap.inc
parent
ac90ec173d
commit
2dd2d36d98
|
@ -443,123 +443,6 @@ function watchdog_exception($type, Exception $exception, $message = NULL, $varia
|
|||
\Drupal::logger($type)->log($severity, $message, $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <em>safe</em> markup string.',
|
||||
* ),
|
||||
* array(
|
||||
* 'safe' => FALSE,
|
||||
* 'message' => "$arbitrary_user_input to escape.",
|
||||
* ),
|
||||
* ),
|
||||
* );
|
||||
* @endcode
|
||||
* If there are no messages set, the function returns NULL.
|
||||
*
|
||||
* @see drupal_get_messages()
|
||||
* @see status-messages.html.twig
|
||||
* @see https://www.drupal.org/node/2774931
|
||||
*
|
||||
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0.
|
||||
* Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
|
||||
*/
|
||||
function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE) {
|
||||
@trigger_error('drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
|
||||
$messenger = \Drupal::messenger();
|
||||
if (isset($message)) {
|
||||
$messenger->addMessage($message, $type, $repeat);
|
||||
}
|
||||
return $messenger->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all messages that have been set with drupal_set_message().
|
||||
*
|
||||
* @param string $type
|
||||
* (optional) Limit the messages returned by type. Defaults to NULL, meaning
|
||||
* all types. These values are supported:
|
||||
* - NULL
|
||||
* - 'status'
|
||||
* - 'warning'
|
||||
* - 'error'
|
||||
* @param 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 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 drupal_set_message()
|
||||
* @see status-messages.html.twig
|
||||
* @see https://www.drupal.org/node/2774931
|
||||
*
|
||||
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0.
|
||||
* Use \Drupal\Core\Messenger\MessengerInterface::all() or
|
||||
* \Drupal\Core\Messenger\MessengerInterface::messagesByType() instead.
|
||||
*/
|
||||
function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
|
||||
@trigger_error('drupal_get_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::all() or \Drupal\Core\Messenger\MessengerInterface::messagesByType() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
|
||||
$messenger = \Drupal::messenger();
|
||||
if ($messages = $messenger->all()) {
|
||||
if ($type) {
|
||||
if ($clear_queue) {
|
||||
$messenger->deleteByType($type);
|
||||
}
|
||||
if (isset($messages[$type])) {
|
||||
return [$type => $messages[$type]];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($clear_queue) {
|
||||
$messenger->deleteAll();
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time zone of the current user.
|
||||
*
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\KernelTests\Core\Common;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @covers ::drupal_set_message
|
||||
* @group Common
|
||||
* @group legacy
|
||||
*/
|
||||
class DrupalSetMessageTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The basic functionality of drupal_set_message().
|
||||
*
|
||||
* @expectedDeprecation drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931
|
||||
* @expectedDeprecation drupal_get_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::all() or \Drupal\Core\Messenger\MessengerInterface::messagesByType() instead. See https://www.drupal.org/node/2774931
|
||||
*/
|
||||
public function testDrupalSetMessage() {
|
||||
drupal_set_message(t('A message: @foo', ['@foo' => 'bar']));
|
||||
$messages = drupal_get_messages();
|
||||
$this->assertInstanceOf('Drupal\Core\Render\Markup', $messages['status'][0]);
|
||||
$this->assertEquals('A message: bar', (string) $messages['status'][0]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue