VerboseMessenger.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Drupal\pathauto;
  3. use Drupal\Core\Config\ConfigFactoryInterface;
  4. use Drupal\Core\Session\AccountInterface;
  5. /**
  6. * Provides a verbose messenger.
  7. */
  8. class VerboseMessenger implements MessengerInterface {
  9. /**
  10. * The verbose flag.
  11. *
  12. * @var bool
  13. */
  14. protected $isVerbose;
  15. /**
  16. * The config factory.
  17. *
  18. * @var \Drupal\Core\Config\ConfigFactoryInterface
  19. */
  20. protected $configFactory;
  21. /**
  22. * The current user account.
  23. *
  24. * @var \Drupal\Core\Session\AccountInterface
  25. */
  26. protected $account;
  27. /**
  28. * Creates a verbose messenger.
  29. */
  30. public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $account) {
  31. $this->configFactory = $config_factory;
  32. $this->account = $account;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function addMessage($message, $op = NULL) {
  38. if (!isset($this->isVerbose)) {
  39. $config = $this->configFactory->get('pathauto.settings');
  40. $this->isVerbose = $config->get('verbose') && $this->account->hasPermission('notify of path changes');
  41. }
  42. if (!$this->isVerbose || (isset($op) && in_array($op, array('bulkupdate', 'return')))) {
  43. return FALSE;
  44. }
  45. if ($message) {
  46. drupal_set_message($message);
  47. }
  48. return TRUE;
  49. }
  50. }