You are here

public function SubscribersInterface::sendMessage in Message Subscribe 8

Process a message and send to subscribed users.

$subscribe_options['uids'] = array(
  1 => array(
    'notifiers' => array(
      'email',
    ),
  ),
);
$context = array(
  'node' => array(
    1,
  ),
  // The node author.
  'user' => array(
    10,
  ),
  // Related taxonomy terms.
  'taxonomy_term' => array(
    100,
    200,
    300,
  ),
);

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object to process subscriptions and send notifications for.

\Drupal\message\MessageInterface $message: The message object.

array $notify_options: (optional) An array of options to be passed to the message notifier service. See `\Drupal\message_notify\MessageNotifier::send()`.

array $subscribe_options: (optional) Array with the following optional values:

  • 'save message' (defaults to TRUE) Determine if the Message should be saved.
  • 'skip context' (defaults to FALSE) determine if extracting basic context should be skipped in `self::getSubscribers()`.
  • 'last uid' (defaults to 0) Only query UIDs greater than this UID.
  • 'uids': Array of user IDs to be processed. Setting this, will cause skipping `self::getSubscribers()` to get the subscribed users.
  • 'range': (defaults to FALSE) limit the number of items to fetch in the subscribers query.
  • 'end time': The timestamp of the time limit for the function to execute. Defaults to FALSE, meaning there is no time limitation.
  • 'use queue': Determine if queue API should be used to
  • 'queue': Set to TRUE to indicate the processing is done via a queue worker.
  • 'entity access: (defaults to TRUE) determine if access to view the entity should be applied when getting the list of subscribed users.
  • 'notify blocked users' (defaults to the global setting in `message_subscribe.settings`) determine whether blocked users should be notified. Typically this should be used in conjunction with 'entity access' to ensure that blocked users don't receive notifications about entities which they used to have access to before they were blocked.
  • 'notify message owner' (defaults to the global setting in `message_subscribe.settings`) determines if the user that created the entity gets notified of their own action. If TRUE the author will get notified.

array $context: (optional) array keyed with the entity type and array of entity IDs as the value. For example, if the event is related to a node entity, the implementing module might pass along with the node itself, the node author and related taxonomy terms.

Example usage.

1 method overrides SubscribersInterface::sendMessage()
Subscribers::sendMessage in src/Subscribers.php
Process a message and send to subscribed users.

File

src/SubscribersInterface.php, line 76

Class

SubscribersInterface
Subscribers service.

Namespace

Drupal\message_subscribe

Code

public function sendMessage(EntityInterface $entity, MessageInterface $message, array $notify_options = [], array $subscribe_options = [], array $context = []);