You are here

public function CourierTemplateCollection::execute in RNG - Events and Registrations 3.x

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

Sends the message.

Parameters

array $context: An associative array defining context.

  • \Drupal\rng\RegistrationInterface[] registrations: An array of registrations to send the message.

Overrides ExecutableInterface::execute

File

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

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\Entity\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();
        if ($identity) {
          $this->courierManager
            ->sendMessage($collection, $identity, $options);
        }
      }
    }
  }
}