You are here

public function Email::deliver in Message Notify 8

Deliver a message via the required transport method.

Parameters

array $output: Array keyed by the view mode, and the rendered entity in the specified view mode.

Return value

bool TRUE or FALSE based on delivery status.

Overrides MessageNotifierInterface::deliver

File

src/Plugin/Notifier/Email.php, line 89

Class

Email
Email notifier.

Namespace

Drupal\message_notify\Plugin\Notifier

Code

public function deliver(array $output = []) {

  /** @var \Drupal\user\UserInterface $account */
  $account = $this->message
    ->getOwner();
  if (!$this->configuration['mail'] && !$account
    ->id()) {

    // The message has no owner and no mail was passed. This will cause an
    // exception, we just make sure it's a clear one.
    throw new MessageNotifyException('It is not possible to send a Message to an anonymous owner. You may set an owner using ::setOwner() or pass a "mail" to the $options array.');
  }
  $mail = $this->configuration['mail'] ?: $account
    ->getEmail();
  $from = $this->configuration['from'] ?: NULL;
  if (!$this->configuration['language override']) {
    $language = $account
      ->getPreferredLangcode();
  }
  else {
    $language = $this->message
      ->language()
      ->getId();
  }

  // The subject in an email can't be with HTML, so strip it.
  $output['mail_subject'] = trim(strip_tags($output['mail_subject']));

  // Pass the message entity along to hook_drupal_mail().
  $output['message_entity'] = $this->message;
  $result = $this->mailManager
    ->mail('message_notify', $this->message
    ->getTemplate()
    ->id(), $mail, $language, $output, $from);
  return $result['result'];
}