Commit fb1c15b1 authored by gbyte's avatar gbyte Committed by Pawel G

Issue #2958710 by Prashant.c: Replace usages of the deprecated drupal_set_message() function

parent 3cad69a3
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\simple_sitemap; namespace Drupal\simple_sitemap;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Session\AccountProxyInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
...@@ -29,6 +30,11 @@ class Logger { ...@@ -29,6 +30,11 @@ class Logger {
*/ */
protected $logger; protected $logger;
/**
* @var \Drupal\Core\Messenger\Messenger
*/
protected $messenger;
/** /**
* @var \Drupal\Core\Session\AccountProxyInterface * @var \Drupal\Core\Session\AccountProxyInterface
*/ */
...@@ -46,15 +52,17 @@ class Logger { ...@@ -46,15 +52,17 @@ class Logger {
/** /**
* Logger constructor. * Logger constructor.
* * @param \Psr\Log\LoggerInterface $logger
* @param $logger * @param \Drupal\Core\Messenger\Messenger $messenger
* @param $current_user * @param \Drupal\Core\Session\AccountProxyInterface $current_user
*/ */
public function __construct( public function __construct(
LoggerInterface $logger, LoggerInterface $logger,
Messenger $messenger,
AccountProxyInterface $current_user AccountProxyInterface $current_user
) { ) {
$this->logger = $logger; $this->logger = $logger;
$this->messenger = $messenger;
$this->currentUser = $current_user; $this->currentUser = $current_user;
} }
...@@ -85,7 +93,7 @@ class Logger { ...@@ -85,7 +93,7 @@ class Logger {
*/ */
public function display($displayMessageType = self::DISPLAY_MESSAGE_TYPE_DEFAULT, $permission = '') { public function display($displayMessageType = self::DISPLAY_MESSAGE_TYPE_DEFAULT, $permission = '') {
if (empty($permission) || $this->currentUser->hasPermission($permission)) { if (empty($permission) || $this->currentUser->hasPermission($permission)) {
drupal_set_message($this->t($this->message, $this->substitutions), $displayMessageType); $this->messenger->addMessage($this->t($this->message, $this->substitutions), $displayMessageType);
} }
return $this; return $this;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment