You are here

private function ActivitySendEmailWorker::sendToFrequencyManager in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.0.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::sendToFrequencyManager()
  2. 10.1.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::sendToFrequencyManager()
  3. 10.2.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::sendToFrequencyManager()

Send the queue items for further processing by frequency managers.

Parameters

array $parameters: The array of message_tempalte_id, current_message_frequency, target_account, activity entity, email body text.

Throws

\Drupal\Component\Plugin\Exception\PluginException

1 call to ActivitySendEmailWorker::sendToFrequencyManager()
ActivitySendEmailWorker::processItem in modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php
Works on a single queue item.

File

modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php, line 248

Class

ActivitySendEmailWorker
An activity send email worker.

Namespace

Drupal\activity_send_email\Plugin\QueueWorker

Code

private function sendToFrequencyManager(array $parameters) {
  if (empty($parameters['target_recipients'])) {
    return;
  }
  $user_storage = $this->entityTypeManager
    ->getStorage('user');
  if (!empty($parameters['langcode'])) {

    // Get the message text according to language.
    $body_text = EmailActivityDestination::getSendEmailOutputText($parameters['message'], $parameters['langcode']);
  }
  else {

    // We get the default body text.
    $body_text = EmailActivityDestination::getSendEmailOutputText($parameters['message']);
  }

  // We load all the target accounts.
  if ($target_accounts = $user_storage
    ->loadMultiple($parameters['target_recipients'])) {

    /** @var \Drupal\user\Entity\User $target_account */
    foreach ($target_accounts as $target_account) {

      // Filter out blocked users early in the process.
      if ($target_account instanceof User && !$target_account
        ->isBlocked()) {

        // If a site manager decides emails should not be sent to users
        // who have never logged in. We need to verify last accessed time,
        // so those users are not processed.
        if ($this->swiftmailSettings
          ->get('do_not_send_emails_new_users') && (int) $target_account
          ->getLastAccessedTime() === 0) {
          continue;
        }

        // Only for users that have access to related content.
        if ($parameters['activity']
          ->getRelatedEntity()
          ->access('view', $target_account)) {

          // If the website is multilingual, get the body text in
          // users preferred language. This will happen when the queue item
          // is not processed in a batch and thus we can't be sure if all
          // users in the queue have the same language.
          if (empty($parameters['langcode']) && $this->languageManager
            ->isMultilingual()) {
            $body_text = EmailActivityDestination::getSendEmailOutputText($parameters['message'], $target_account
              ->getPreferredLangcode());
          }

          // Send item to EmailFrequency instance.
          $instance = $this->frequencyManager
            ->createInstance($parameters['frequency']);
          $instance
            ->processItem($parameters['activity'], $parameters['message'], $target_account, $body_text);
        }
      }
    }
  }
}