3 namespace Drupal\simple_sitemap;
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6 use Drupal\Core\Session\AccountProxyInterface;
7 use Psr\Log\LoggerInterface;
11 * @package Drupal\simple_sitemap
15 use StringTranslationTrait;
18 * Can be debug/info/notice/warning/error.
20 const LOG_SEVERITY_LEVEL_DEFAULT = 'notice';
23 * Can be status/warning/error.
25 const DISPLAY_MESSAGE_TYPE_DEFAULT = 'status';
28 * @var \Psr\Log\LoggerInterface
33 * @var \Drupal\Core\Session\AccountProxyInterface
35 protected $currentUser;
40 protected $message = '';
45 protected $substitutions = [];
51 * @param $current_user
53 public function __construct(
54 LoggerInterface $logger,
55 AccountProxyInterface $current_user
57 $this->logger = $logger;
58 $this->currentUser = $current_user;
63 * @param array $substitutions
66 public function m($message, $substitutions = []) {
67 $this->message = $message;
68 $this->substitutions = $substitutions;
73 * @param string $logSeverityLevel
76 public function log($logSeverityLevel = self::LOG_SEVERITY_LEVEL_DEFAULT) {
77 $this->logger->$logSeverityLevel(strtr($this->message, $this->substitutions));
82 * @param string $displayMessageType
83 * @param string $permission
86 public function display($displayMessageType = self::DISPLAY_MESSAGE_TYPE_DEFAULT, $permission = '') {
87 if (empty($permission) || $this->currentUser->hasPermission($permission)) {
88 drupal_set_message($this->t($this->message, $this->substitutions), $displayMessageType);