You are here

public function PrivateMessageMailer::send in Private Message 8

Send a private message notification email.

Parameters

\Drupal\private_message\Entity\PrivateMessageInterface $message: The message.

\Drupal\private_message\Entity\PrivateMessageThreadInterface $thread: The message thread.

\Drupal\user\UserInterface[] $members: The message members.

Overrides PrivateMessageMailerInterface::send

File

src/Service/PrivateMessageMailer.php, line 84

Class

PrivateMessageMailer
A service class for sending notification emails for private messages.

Namespace

Drupal\private_message\Service

Code

public function send(PrivateMessageInterface $message, PrivateMessageThreadInterface $thread, array $members = []) {
  $params = [
    'private_message' => $message,
    'private_message_thread' => $thread,
  ];

  // Remove the current user from the members array.
  $members = array_filter($members, function (AccountInterface $member) {
    return $member
      ->id() !== $this->currentUser
      ->id();
  });
  foreach ($members as $member) {
    $params['member'] = $member;
    if ($this
      ->shouldSend($member)) {
      $this->mailManager
        ->mail('private_message', 'message_notification', $member
        ->getEmail(), $member
        ->getPreferredLangcode(), $params);
    }
  }
}