You are here

public function SocialEventAnEnrollSendEmail::executeMultiple in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_an_enroll/src/Plugin/Action/SocialEventAnEnrollSendEmail.php \Drupal\social_event_an_enroll\Plugin\Action\SocialEventAnEnrollSendEmail::executeMultiple()
  2. 8.8 modules/social_features/social_event/modules/social_event_an_enroll/src/Plugin/Action/SocialEventAnEnrollSendEmail.php \Drupal\social_event_an_enroll\Plugin\Action\SocialEventAnEnrollSendEmail::executeMultiple()
  3. 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/src/Plugin/Action/SocialEventAnEnrollSendEmail.php \Drupal\social_event_an_enroll\Plugin\Action\SocialEventAnEnrollSendEmail::executeMultiple()
  4. 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/src/Plugin/Action/SocialEventAnEnrollSendEmail.php \Drupal\social_event_an_enroll\Plugin\Action\SocialEventAnEnrollSendEmail::executeMultiple()
  5. 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/src/Plugin/Action/SocialEventAnEnrollSendEmail.php \Drupal\social_event_an_enroll\Plugin\Action\SocialEventAnEnrollSendEmail::executeMultiple()

Executes the plugin for an array of objects.

Parameters

array $objects: An array of entities.

Overrides SocialEventManagersSendEmail::executeMultiple

File

modules/social_features/social_event/modules/social_event_an_enroll/src/Plugin/Action/SocialEventAnEnrollSendEmail.php, line 120

Class

SocialEventAnEnrollSendEmail
Send email to event enrollment users.

Namespace

Drupal\social_event_an_enroll\Plugin\Action

Code

public function executeMultiple(array $objects) {
  $guests = [];
  foreach ($objects as $key => $entity) {
    if ($this->socialEventAnEnrollManager
      ->isGuest($entity)) {
      $guests[$key] = [
        'email_address' => $entity->field_email->value,
        'display_name' => $this
          ->getDisplayName($entity),
      ];
    }
  }
  if (!empty($guests)) {

    // Create some chunks and then make queue items.
    $chunk_size = Settings::get('social_mail_chunk_size', 10);
    $chunks = array_chunk($guests, $chunk_size);
    foreach ($chunks as $chunk) {

      // Get the entity ID of the email that is send.
      $data['mail'] = $this->configuration['queue_storage_id'];

      // Add the list of user IDs.
      $data['user_mail_addresses'] = $chunk;

      // Put the $data in the queue item.

      /** @var \Drupal\Core\Queue\QueueInterface $queue */
      $queue = $this->queue
        ->get('user_email_queue');
      $queue
        ->createItem($data);
    }
  }

  // Before parent remove the guest from the objects list.
  // Otherwise they will be processed as users and it will break as there
  // is no user account.
  $objects = array_diff_key($objects, array_keys($guests));

  // Execute parent as we still need to check if there are users enrolled.
  return parent::executeMultiple($objects);
}