You are here

public function MassContact::queueRecipients in Mass Contact 8

Takes a mass contact, calculates recipients and queues them for delivery.

Parameters

\Drupal\mass_contact\Entity\MassContactMessageInterface $message: The mass contact message entity.

array $configuration: An array of configuration. Default values are provided by the mass contact settings.

Overrides MassContactInterface::queueRecipients

File

src/MassContact.php, line 171

Class

MassContact
The Mass Contact helper service.

Namespace

Drupal\mass_contact

Code

public function queueRecipients(MassContactMessageInterface $message, array $configuration = []) {

  // Add defaults.
  $configuration += $this
    ->getDefaultConfiguration();
  $data = [
    'message' => $message,
    'configuration' => $configuration,
  ];
  $all_recipients = $this
    ->getRecipients($message
    ->getCategories(), $configuration['respect_opt_out']);
  $send_me_copy_user = $data['configuration']['send_me_copy_user'];
  if ($send_me_copy_user) {

    // Add the sender's email to the recipient list if 'Send yourself a copy'
    // option has been chosen AND the email is not already in the recipient
    // list.
    // Add this user as the first user in the list. If the user exists in the
    // recipient list, remove the user and add the user again as first in the
    // list.
    if (!empty($all_recipients)) {
      $send_me_copy_user_key = array_search($send_me_copy_user, $all_recipients);
      if ($send_me_copy_user_key !== FALSE) {
        unset($all_recipients[$send_me_copy_user_key]);
      }
    }
    $all_recipients = [
      $send_me_copy_user => $send_me_copy_user,
    ] + $all_recipients;
  }
  foreach ($this
    ->getGroupedRecipients($all_recipients) as $recipients) {
    $data['recipients'] = $recipients;
    $this->sendingQueue
      ->createItem($data);
  }
}