You are here

public function Mailer::sendCombinedConfirmation in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/Mail/Mailer.php \Drupal\simplenews\Mail\Mailer::sendCombinedConfirmation()
  2. 3.x src/Mail/Mailer.php \Drupal\simplenews\Mail\Mailer::sendCombinedConfirmation()

Send collected confirmations.

Depending on the settings, always sends a combined confirmation, only when there are multiple changes for a subscriber or never.

@todo This function currently does not return information about which subscriber received a confirmation.

Return value

bool TRUE if any confirmation mails have been sent.

Overrides MailerInterface::sendCombinedConfirmation

File

src/Mail/Mailer.php, line 406

Class

Mailer
Default Mailer.

Namespace

Drupal\simplenews\Mail

Code

public function sendCombinedConfirmation(SubscriberInterface $subscriber) {
  $params['from'] = $this
    ->getFrom();
  $params['context']['simplenews_subscriber'] = $subscriber;

  // Send multiple if there is more than one change for this subscriber
  // single otherwise.
  $use_combined = $this->config
    ->get('subscription.use_combined');
  $changes = $subscriber
    ->getChanges();
  if (count($changes) > 1 && $use_combined != 'never' || $use_combined == 'always') {
    $key = 'subscribe_combined';
    $this->mailManager
      ->mail('simplenews', $key, $subscriber
      ->getMail(), $subscriber
      ->getLangcode(), $params, $params['from']['address']);
  }
  else {
    foreach ($changes as $newsletter_id => $key) {
      $params['context']['newsletter'] = Newsletter::load($newsletter_id);
      $this->mailManager
        ->mail('simplenews', $key, $subscriber
        ->getMail(), $subscriber
        ->getLangcode(), $params, $params['from']['address']);
    }
  }
}