VerboseMessenger.php in Pathauto 8
File
src/VerboseMessenger.php
View source
<?php
namespace Drupal\pathauto;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Messenger\MessengerInterface as CoreMessengerInterface;
use Drupal\Core\Session\AccountInterface;
class VerboseMessenger implements MessengerInterface {
protected $isVerbose;
protected $configFactory;
protected $account;
protected $messenger;
public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $account, CoreMessengerInterface $messenger) {
$this->configFactory = $config_factory;
$this->account = $account;
$this->messenger = $messenger;
}
public function addMessage($message, $op = NULL) {
if (!isset($this->isVerbose)) {
$config = $this->configFactory
->get('pathauto.settings');
$this->isVerbose = $config
->get('verbose') && $this->account
->hasPermission('notify of path changes');
}
if (!$this->isVerbose || isset($op) && in_array($op, [
'bulkupdate',
'return',
])) {
return FALSE;
}
if ($message) {
$this->messenger
->addMessage($message);
}
return TRUE;
}
}