You are here

public function MassContact::getRecipients in Mass Contact 8

Given categories, returns an array of recipient IDs.

Parameters

\Drupal\mass_contact\Entity\MassContactCategoryInterface[] $categories: An array of mass contact categories.

bool $respect_opt_out: Whether to respect opt outs when getting the list of recipients.

Return value

int[] An array of recipient user IDs.

Overrides MassContactInterface::getRecipients

1 call to MassContact::getRecipients()
MassContact::queueRecipients in src/MassContact.php
Takes a mass contact, calculates recipients and queues them for delivery.

File

src/MassContact.php, line 230

Class

MassContact
The Mass Contact helper service.

Namespace

Drupal\mass_contact

Code

public function getRecipients(array $categories, $respect_opt_out) {
  $recipients = [];
  if (!empty($categories)) {
    foreach ($categories as $category) {
      $category_recipients = [];
      foreach ($category
        ->getRecipients() as $plugin_id => $config) {
        $grouping = $category
          ->getGroupingCategories($plugin_id);
        if (!empty($config['categories'])) {

          // Only If values were chosen for this grouping in this category,
          // we gather recipients.
          $category_recipients[$plugin_id] = $grouping
            ->getRecipients($config['categories']);
        }
      }
      $recipients += count($category_recipients) > 1 ? call_user_func_array('array_intersect', $category_recipients) : reset($category_recipients);
    }

    // Filter out users that have opted out only if sender has chosen to
    // respect opt outs.
    if ($respect_opt_out) {
      return array_diff_key($recipients, $this->optOut
        ->getOptOutAccounts($categories));
    }
  }
  return $recipients;
}