You are here

class ContentHubExportQueueMessageSubscriber in Acquia Content Hub 8

Class ContentHubExportQueueMessageSubscriber.

This class catches kernel.request events and displays messages from enabled plugins.

@package Drupal\admin_status

Hierarchy

Expanded class hierarchy of ContentHubExportQueueMessageSubscriber

1 string reference to 'ContentHubExportQueueMessageSubscriber'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses ContentHubExportQueueMessageSubscriber
acquia_contenthub.export_queue_message in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\ContentHubExportQueueMessageSubscriber

File

src/EventSubscriber/ContentHubExportQueueMessageSubscriber.php, line 20

Namespace

Drupal\acquia_contenthub\EventSubscriber
View source
class ContentHubExportQueueMessageSubscriber implements EventSubscriberInterface {
  use StringTranslationTrait;

  /**
   * The Content Hub Export Queue Controller.
   *
   * @var \Drupal\acquia_contenthub\Controller\ContentHubExportQueueController
   */
  protected $contentHubExportQueueController;

  /**
   * The Drupal Messenger Service.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  private $messenger;

  /**
   * The current request path.
   *
   * @var \Drupal\Core\Path\CurrentPathStack
   */
  private $currentPath;

  /**
   * Construct an ContentHubExportQueueMessageSubscriber object.
   *
   * @param \Drupal\acquia_contenthub\Controller\ContentHubExportQueueController $export_queue_controller
   *   The Content Hub Export Queue Controller.
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   Messenger Service.
   * @param \Drupal\Core\Path\CurrentPathStack $current_path
   *   Current Path Service.
   */
  public function __construct(ContentHubExportQueueController $export_queue_controller, MessengerInterface $messenger, CurrentPathStack $current_path) {
    $this->contentHubExportQueueController = $export_queue_controller;
    $this->messenger = $messenger;
    $this->currentPath = $current_path;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Tell Symfony that we want to hear about kernel.request events.
    $events['kernel.request'] = [
      'kernelRequest',
    ];
    return $events;
  }

  /**
   * Handles kernel.request events.
   *
   * @param \Symfony\Component\EventDispatcher\Event $event
   *   The Symfony event.
   */
  public function kernelRequest(Event $event) {

    // Get our saved config data.
    $queue_items = $this->contentHubExportQueueController
      ->getQueueCount();

    // Get current path.
    $current_path = $this->currentPath
      ->getPath();

    // If we are processing the queue, then drop warning messages so they will
    // not pile up at every queue run.
    if ($current_path === '/admin/config/services/acquia-contenthub/export-queue') {
      $this->messenger
        ->messagesByType('warning');
    }
    if ($this
      ->currentUser()
      ->hasPermission('administer acquia content hub') && $queue_items > 1) {
      $message = $this
        ->t('You have %items items in the <a href="@link">Content Hub Export Queue</a>. Make sure to export those items to keep your system up to date.', [
        '%items' => $queue_items,
        '@link' => '/admin/config/services/acquia-contenthub/export-queue',
      ]);
      $this->messenger
        ->addWarning($message);
    }
  }

  /**
   * Obtains the current user.
   *
   * @return \Drupal\Core\Session\AccountProxyInterface
   *   The current user object.
   */
  protected function currentUser() {
    return \Drupal::currentUser();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentHubExportQueueMessageSubscriber::$contentHubExportQueueController protected property The Content Hub Export Queue Controller.
ContentHubExportQueueMessageSubscriber::$currentPath private property The current request path.
ContentHubExportQueueMessageSubscriber::$messenger private property The Drupal Messenger Service.
ContentHubExportQueueMessageSubscriber::currentUser protected function Obtains the current user.
ContentHubExportQueueMessageSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ContentHubExportQueueMessageSubscriber::kernelRequest public function Handles kernel.request events.
ContentHubExportQueueMessageSubscriber::__construct public function Construct an ContentHubExportQueueMessageSubscriber object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.