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
- class \Drupal\acquia_contenthub\EventSubscriber\ContentHubExportQueueMessageSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of ContentHubExportQueueMessageSubscriber
1 string reference to 'ContentHubExportQueueMessageSubscriber'
1 service uses ContentHubExportQueueMessageSubscriber
File
- src/
EventSubscriber/ ContentHubExportQueueMessageSubscriber.php, line 20
Namespace
Drupal\acquia_contenthub\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentHubExportQueueMessageSubscriber:: |
protected | property | The Content Hub Export Queue Controller. | |
ContentHubExportQueueMessageSubscriber:: |
private | property | The current request path. | |
ContentHubExportQueueMessageSubscriber:: |
private | property | The Drupal Messenger Service. | |
ContentHubExportQueueMessageSubscriber:: |
protected | function | Obtains the current user. | |
ContentHubExportQueueMessageSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ContentHubExportQueueMessageSubscriber:: |
public | function | Handles kernel.request events. | |
ContentHubExportQueueMessageSubscriber:: |
public | function | Construct an ContentHubExportQueueMessageSubscriber object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |