Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / src / VerboseMessenger.php
1 <?php
2
3 namespace Drupal\pathauto;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Messenger\MessengerInterface as CoreMessengerInterface;
7 use Drupal\Core\Session\AccountInterface;
8
9 /**
10  * Provides a verbose messenger.
11  */
12 class VerboseMessenger implements MessengerInterface {
13
14   /**
15    * The verbose flag.
16    *
17    * @var bool
18    */
19   protected $isVerbose;
20
21   /**
22    * The config factory.
23    *
24    * @var \Drupal\Core\Config\ConfigFactoryInterface
25    */
26   protected $configFactory;
27
28   /**
29    * The current user account.
30    *
31    * @var \Drupal\Core\Session\AccountInterface
32    */
33   protected $account;
34
35   /**
36    * The messenger service.
37    *
38    * @var \Drupal\Core\Messenger\MessengerInterface
39    */
40   protected $messenger;
41
42   /**
43    * Creates a verbose messenger.
44    *
45    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
46    *   The config factory.
47    * @param \Drupal\Core\Session\AccountInterface $account
48    *   The current user account.
49    * @param \Drupal\Core\Messenger\MessengerInterface $messenger
50    *   The messenger service.
51    */
52   public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $account, CoreMessengerInterface $messenger) {
53     $this->configFactory = $config_factory;
54     $this->account = $account;
55     $this->messenger = $messenger;
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function addMessage($message, $op = NULL) {
62
63     if (!isset($this->isVerbose)) {
64       $config = $this->configFactory->get('pathauto.settings');
65       $this->isVerbose = $config->get('verbose') && $this->account->hasPermission('notify of path changes');
66     }
67
68     if (!$this->isVerbose || (isset($op) && in_array($op, array('bulkupdate', 'return')))) {
69       return FALSE;
70     }
71
72     if ($message) {
73       $this->messenger->addMessage($message);
74     }
75
76     return TRUE;
77   }
78
79 }