You are here

function MailBuilder::buildUnsubscribeMail in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Mail/MailBuilder.php \Drupal\simplenews\Mail\MailBuilder::buildUnsubscribeMail()

Build subject and body of the unsubscribe confirmation email.

Parameters

array $message: Message array as used by hook_mail().

array $params: Parameter array as used by hook_mail().

Overrides MailBuilderInterface::buildUnsubscribeMail

File

src/Mail/MailBuilder.php, line 142

Class

MailBuilder
Default mail builder.

Namespace

Drupal\simplenews\Mail

Code

function buildUnsubscribeMail(&$message, $params) {
  $context = $params['context'];

  // Use formatted from address "name" <mail_address>
  $message['headers']['From'] = $params['from']['formatted'];
  $message['subject'] = $this->config
    ->get('subscription.confirm_subscribe_subject');
  $message['subject'] = $this->token
    ->replace($message['subject'], $context, array(
    'sanitize' => FALSE,
  ));
  if ($context['simplenews_subscriber']
    ->isSubscribed($context['newsletter']
    ->id())) {
    $body = $this->config
      ->get('subscription.confirm_unsubscribe_subscribed');
    $message['body'][] = $this->token
      ->replace($body, $context, array(
      'sanitize' => FALSE,
    ));
  }
  else {
    $body = $this->config
      ->get('subscription.confirm_unsubscribe_unsubscribed');
    $message['body'][] = $this->token
      ->replace($body, $context, array(
      'sanitize' => FALSE,
    ));
  }
}