You are here

class DispatchService in RNG - Events and Registrations 3.x

Class DispatchService.

Hierarchy

Expanded class hierarchy of DispatchService

1 file declares its use of DispatchService
RegistrationSubscriber.php in rng_easy_email/src/EventSubscriber/RegistrationSubscriber.php
1 string reference to 'DispatchService'
rng_easy_email.services.yml in rng_easy_email/rng_easy_email.services.yml
rng_easy_email/rng_easy_email.services.yml
1 service uses DispatchService
rng_easy_email.dispatch in rng_easy_email/rng_easy_email.services.yml
Drupal\rng_easy_email\DispatchService

File

rng_easy_email/src/DispatchService.php, line 13

Namespace

Drupal\rng_easy_email
View source
class DispatchService {

  /**
   * Drupal\easy_email\Service\EmailHandlerInterface definition.
   *
   * @var \Drupal\easy_email\Service\EmailHandlerInterface
   */
  protected $easyEmailHandler;

  /**
   * Constructs a new DispatchService object.
   */
  public function __construct(EmailHandlerInterface $easy_email_handler) {
    $this->easyEmailHandler = $easy_email_handler;
  }
  public function send($template, RegistrantInterface $registrant) {
    $email = $this->easyEmailHandler
      ->createEmail([
      'type' => $template,
      'field_registrant' => $registrant
        ->id(),
      'field_registration' => $registrant
        ->getRegistration()
        ->id(),
      'field_event' => $registrant
        ->getEvent()
        ->id(),
    ]);
    if (!$this->easyEmailHandler
      ->duplicateExists($email)) {
      $this->easyEmailHandler
        ->sendEmail($email);
    }
  }
  public function sendRegistration($template, RegistrationInterface $registration) {

    // Don't send for events in the past, to allow import of old registrants.
    $event = $registration
      ->getEventMeta();
    if ($event
      ->isPastEvent()) {
      return;
    }
    foreach ($registration
      ->getRegistrants() as $registrant) {
      $this
        ->send($template, $registrant);
    }
  }
  public function sendEvent($template, ContentEntityInterface $contentEntity) {
  }

}

Members