You are here

public function SocialSendEmail::executeMultiple in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
  2. 10.3.x modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
  3. 10.0.x modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
  4. 10.1.x modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
  5. 10.2.x modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
1 call to SocialSendEmail::executeMultiple()
SocialEventManagersSendEmail::executeMultiple in modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/SocialEventManagersSendEmail.php
1 method overrides SocialSendEmail::executeMultiple()
SocialEventManagersSendEmail::executeMultiple in modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/SocialEventManagersSendEmail.php

File

modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php, line 146

Class

SocialSendEmail
An example action covering most of the possible options.

Namespace

Drupal\social_user\Plugin\Action

Code

public function executeMultiple(array $objects) {

  // Array $objects contain all the entities of this bulk operation batch.
  // We want smaller queue items then this so we chunk these.
  // @todo: make the chunk size configurable or dependable on the batch size.
  $chunk_size = 10;
  $chunks = array_chunk($objects, $chunk_size);
  foreach ($chunks as $chunk) {
    $users = [];

    // The chunk items contain entities, we want to perform an action on this.
    foreach ($chunk as $entity) {

      // The action retrieves the user ID of the user.
      $users[] = $this
        ->execute($entity);
    }

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

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

    // Put the $data in the queue item.

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

  // Add a clarifying message.
  $this
    ->messenger()
    ->addMessage($this
    ->t('The email(s) will be send in the background. You will be notified upon completion.'));
  return [];
}