Version 1
[yaffs-website] / web / modules / contrib / pathauto / src / VerboseMessenger.php
diff --git a/web/modules/contrib/pathauto/src/VerboseMessenger.php b/web/modules/contrib/pathauto/src/VerboseMessenger.php
new file mode 100644 (file)
index 0000000..bc60b5c
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+namespace Drupal\pathauto;
+
+use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Provides a verbose messenger.
+ */
+class VerboseMessenger implements MessengerInterface {
+
+  /**
+   * The verbose flag.
+   *
+   * @var bool
+   */
+  protected $isVerbose;
+
+  /**
+   * The config factory.
+   *
+   * @var \Drupal\Core\Config\ConfigFactoryInterface
+   */
+  protected $configFactory;
+
+  /**
+   * The current user account.
+   *
+   * @var \Drupal\Core\Session\AccountInterface
+   */
+  protected $account;
+
+  /**
+   * Creates a verbose messenger.
+   */
+  public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $account) {
+    $this->configFactory = $config_factory;
+    $this->account = $account;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  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, array('bulkupdate', 'return')))) {
+      return FALSE;
+    }
+
+    if ($message) {
+      drupal_set_message($message);
+    }
+
+    return TRUE;
+  }
+
+}