Interim commit.
[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\Session\AccountInterface;
7
8 /**
9  * Provides a verbose messenger.
10  */
11 class VerboseMessenger implements MessengerInterface {
12
13   /**
14    * The verbose flag.
15    *
16    * @var bool
17    */
18   protected $isVerbose;
19
20   /**
21    * The config factory.
22    *
23    * @var \Drupal\Core\Config\ConfigFactoryInterface
24    */
25   protected $configFactory;
26
27   /**
28    * The current user account.
29    *
30    * @var \Drupal\Core\Session\AccountInterface
31    */
32   protected $account;
33
34   /**
35    * Creates a verbose messenger.
36    */
37   public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $account) {
38     $this->configFactory = $config_factory;
39     $this->account = $account;
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function addMessage($message, $op = NULL) {
46
47     if (!isset($this->isVerbose)) {
48       $config = $this->configFactory->get('pathauto.settings');
49       $this->isVerbose = $config->get('verbose') && $this->account->hasPermission('notify of path changes');
50     }
51
52     if (!$this->isVerbose || (isset($op) && in_array($op, array('bulkupdate', 'return')))) {
53       return FALSE;
54     }
55
56     if ($message) {
57       drupal_set_message($message);
58     }
59
60     return TRUE;
61   }
62
63 }