ContentHubExportQueueMessageSubscriber.php in Acquia Content Hub 8
File
src/EventSubscriber/ContentHubExportQueueMessageSubscriber.php
View source
<?php
namespace Drupal\acquia_contenthub\EventSubscriber;
use Drupal\acquia_contenthub\Controller\ContentHubExportQueueController;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ContentHubExportQueueMessageSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
protected $contentHubExportQueueController;
private $messenger;
private $currentPath;
public function __construct(ContentHubExportQueueController $export_queue_controller, MessengerInterface $messenger, CurrentPathStack $current_path) {
$this->contentHubExportQueueController = $export_queue_controller;
$this->messenger = $messenger;
$this->currentPath = $current_path;
}
public static function getSubscribedEvents() {
$events['kernel.request'] = [
'kernelRequest',
];
return $events;
}
public function kernelRequest(Event $event) {
$queue_items = $this->contentHubExportQueueController
->getQueueCount();
$current_path = $this->currentPath
->getPath();
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);
}
}
protected function currentUser() {
return \Drupal::currentUser();
}
}