You are here

public function EmailUserEvaluator::evaluateUsers in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x src/Service/EmailUserEvaluator.php \Drupal\easy_email\Service\EmailUserEvaluator::evaluateUsers()

@inheritDoc

Overrides EmailUserEvaluatorInterface::evaluateUsers

File

src/Service/EmailUserEvaluator.php, line 47

Class

EmailUserEvaluator

Namespace

Drupal\easy_email\Service

Code

public function evaluateUsers(EasyEmailInterface $email) {
  $this->eventDispatcher
    ->dispatch(EasyEmailEvents::EMAIL_PREUSEREVAL, new EasyEmailEvent($email));
  if ($email
    ->hasField('recipient_uid')) {
    $recipients = $email
      ->getRecipientAddresses();
    if (!empty($recipients)) {
      $results = $this->userStorage
        ->getQuery()
        ->condition('mail', $recipients, 'IN')
        ->execute();
      if (!empty($results)) {
        $email
          ->setRecipientIds(array_keys($results));
      }
    }
  }
  if ($email
    ->hasField('cc_uid')) {
    $cc = $email
      ->getCCAddresses();
    if (!empty($cc)) {
      $results = $this->userStorage
        ->getQuery()
        ->condition('mail', $cc, 'IN')
        ->execute();
      if (!empty($results)) {
        $email
          ->setCCIds(array_keys($results));
      }
    }
  }
  if ($email
    ->hasField('bcc_uid')) {
    $bcc = $email
      ->getBCCAddresses();
    if (!empty($bcc)) {
      $results = $this->userStorage
        ->getQuery()
        ->condition('mail', $bcc, 'IN')
        ->execute();
      if (!empty($results)) {
        $email
          ->setBCCIds(array_keys($results));
      }
    }
  }
  $this->eventDispatcher
    ->dispatch(EasyEmailEvents::EMAIL_USEREVAL, new EasyEmailEvent($email));
}