You are here

public function EmailTokenEvaluator::evaluateTokens in Easy Email 2.0.x

Same name and namespace in other branches
  1. 8 src/Service/EmailTokenEvaluator.php \Drupal\easy_email\Service\EmailTokenEvaluator::evaluateTokens()

@inheritDoc

Overrides EmailTokenEvaluatorInterface::evaluateTokens

File

src/Service/EmailTokenEvaluator.php, line 40

Class

EmailTokenEvaluator

Namespace

Drupal\easy_email\Service

Code

public function evaluateTokens(EasyEmailInterface $email) {
  $this->eventDispatcher
    ->dispatch(EasyEmailEvents::EMAIL_PRETOKENEVAL, new EasyEmailEvent($email));
  if ($email
    ->hasField('key')) {
    $email
      ->setKey($this
      ->replaceTokens($email, $email
      ->getKey()));
  }
  $email
    ->setRecipientAddresses($this
    ->replaceTokens($email, $email
    ->getRecipientAddresses(), TRUE));
  $email
    ->setCCAddresses($this
    ->replaceTokens($email, $email
    ->getCCAddresses(), TRUE));
  $email
    ->setBCCAddresses($this
    ->replaceTokens($email, $email
    ->getBCCAddresses(), TRUE));
  $email
    ->setFromName($this
    ->replaceTokens($email, $email
    ->getFromName()));
  $email
    ->setFromAddress($this
    ->replaceTokens($email, $email
    ->getFromAddress()));
  $email
    ->setReplyToAddress($this
    ->replaceTokens($email, $email
    ->getReplyToAddress()));
  $email
    ->setSubject($this
    ->replaceTokens($email, $email
    ->getSubject()));
  if ($email
    ->hasField('body_html')) {
    $html_body = $email
      ->getHtmlBody();
    $email
      ->setHtmlBody($this
      ->replaceTokens($email, $html_body['value']), $html_body['format']);
  }
  if ($email
    ->hasField('body_plain')) {
    $email
      ->setPlainBody($this
      ->replaceTokens($email, $email
      ->getPlainBody()));
  }
  if ($email
    ->hasField('inbox_preview')) {
    $email
      ->setInboxPreview($this
      ->replaceTokens($email, $email
      ->getInboxPreview()));
  }
  if ($email
    ->hasField('attachment_path')) {
    $email
      ->setAttachmentPaths($this
      ->replaceTokens($email, $email
      ->getAttachmentPaths()));
  }
  $this->eventDispatcher
    ->dispatch(EasyEmailEvents::EMAIL_TOKENEVAL, new EasyEmailEvent($email));
}