You are here

class MessageSubscribe in Message Subscribe 8

Queue worker to process sending of message subscriptions.

Plugin annotation


@QueueWorker(
  id = "message_subscribe",
  title = @Translation("Process bounced emails"),
  cron = {"time" = 60}
)

Hierarchy

Expanded class hierarchy of MessageSubscribe

File

src/Plugin/QueueWorker/MessageSubscribe.php, line 19

Namespace

Drupal\message_subscribe\Plugin\QueueWorker
View source
class MessageSubscribe extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The message subscription service.
   *
   * @var \Drupal\message_subscribe\SubscribersInterface
   */
  protected $subscribers;

  /**
   * Constructs the queue worker.
   *
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, SubscribersInterface $subscribers) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->subscribers = $subscribers;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $message = $data['message'];
    $entity = $data['entity'];
    $notify_options = $data['notify_options'];
    $subscribe_options = $data['subscribe_options'];
    $context = $data['context'];

    // Reload message and entity.
    $message = $message
      ->load($message
      ->id());
    $entity = $entity
      ->load($entity
      ->id());
    if (!$entity || !$message) {
      return;
    }

    // Denotes this is being processed from a queue worker.
    $subscribe_options['queue'] = TRUE;
    $this->subscribers
      ->sendMessage($entity, $message, $notify_options, $subscribe_options, $context);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessageSubscribe::$subscribers protected property The message subscription service.
MessageSubscribe::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
MessageSubscribe::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
MessageSubscribe::__construct public function Constructs the queue worker. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.