MessageSubscribe.php in Message Subscribe 8
File
src/Plugin/QueueWorker/MessageSubscribe.php
View source
<?php
namespace Drupal\message_subscribe\Plugin\QueueWorker;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\message_subscribe\SubscribersInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MessageSubscribe extends QueueWorkerBase implements ContainerFactoryPluginInterface {
protected $subscribers;
public function __construct(array $configuration, $plugin_id, $plugin_definition, SubscribersInterface $subscribers) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->subscribers = $subscribers;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('message_subscribe.subscribers'));
}
public function processItem($data) {
$message = $data['message'];
$entity = $data['entity'];
$notify_options = $data['notify_options'];
$subscribe_options = $data['subscribe_options'];
$context = $data['context'];
$message = $message
->load($message
->id());
$entity = $entity
->load($entity
->id());
if (!$entity || !$message) {
return;
}
$subscribe_options['queue'] = TRUE;
$this->subscribers
->sendMessage($entity, $message, $notify_options, $subscribe_options, $context);
}
}