You are here

class VerboseMessenger in Pathauto 8

Provides a verbose messenger.

Hierarchy

Expanded class hierarchy of VerboseMessenger

1 file declares its use of VerboseMessenger
VerboseMessengerTest.php in tests/src/Unit/VerboseMessengerTest.php
1 string reference to 'VerboseMessenger'
pathauto.services.yml in ./pathauto.services.yml
pathauto.services.yml
1 service uses VerboseMessenger
pathauto.verbose_messenger in ./pathauto.services.yml
Drupal\pathauto\VerboseMessenger

File

src/VerboseMessenger.php, line 12

Namespace

Drupal\pathauto
View source
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;

  /**
   * The messenger service.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * Creates a verbose messenger.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The current user account.
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $account, CoreMessengerInterface $messenger) {
    $this->configFactory = $config_factory;
    $this->account = $account;
    $this->messenger = $messenger;
  }

  /**
   * {@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, [
      'bulkupdate',
      'return',
    ])) {
      return FALSE;
    }
    if ($message) {
      $this->messenger
        ->addMessage($message);
    }
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
VerboseMessenger::$account protected property The current user account.
VerboseMessenger::$configFactory protected property The config factory.
VerboseMessenger::$isVerbose protected property The verbose flag.
VerboseMessenger::$messenger protected property The messenger service.
VerboseMessenger::addMessage public function Adds a message. Overrides MessengerInterface::addMessage
VerboseMessenger::__construct public function Creates a verbose messenger.