You are here

public function CourierTemplateCollection::execute in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Action/CourierTemplateCollection.php \Drupal\rng\Plugin\Action\CourierTemplateCollection::execute()
  2. 3.x src/Plugin/Action/CourierTemplateCollection.php \Drupal\rng\Plugin\Action\CourierTemplateCollection::execute()

Sends the message.

Parameters

array $context: An associative array defining context.

Overrides ExecutableInterface::execute

File

src/Plugin/Action/CourierTemplateCollection.php, line 136

Class

CourierTemplateCollection
Creates a template collection and provides a user interface to its templates.

Namespace

Drupal\rng\Plugin\Action

Code

public function execute($context = NULL) {
  if (!isset($context['registrations'])) {
    return;
  }
  if (!is_array($context['registrations'])) {
    return;
  }
  if ($collection_original = $this
    ->getTemplateCollection()) {
    foreach ($context['registrations'] as $registration) {
      $options = [];

      /** @var \Drupal\rng\RegistrationInterface $registration */
      if (($event = $registration
        ->getEvent()) instanceof EntityInterface) {
        $event_meta = $this->eventManager
          ->getMeta($event);
        $options['channels']['courier_email']['reply_to'] = $event_meta
          ->getReplyTo();
        $collection_original
          ->setTokenValue($event
          ->getEntityTypeId(), $event);
      }
      $collection = clone $collection_original;
      $collection
        ->setTokenValue('registration', $registration);
      foreach ($registration
        ->getRegistrants() as $registrant) {
        $identity = $registrant
          ->getIdentity();
        $this->courierManager
          ->sendMessage($collection, $identity, $options);
      }
    }
  }
}