You are here

public function SocialSendEmail::executeMultiple in Open Social 10.1.x

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. 8.8 modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
  3. 10.3.x modules/social_features/social_user/src/Plugin/Action/SocialSendEmail.php \Drupal\social_user\Plugin\Action\SocialSendEmail::executeMultiple()
  4. 10.0.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()

Executes the plugin for an array of objects.

Parameters

array $objects: An array of entities.

Overrides ViewsBulkOperationsActionBase::executeMultiple

1 call to SocialSendEmail::executeMultiple()
SocialEventManagersSendEmail::executeMultiple in modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/SocialEventManagersSendEmail.php
Execute action on multiple entities.
1 method overrides SocialSendEmail::executeMultiple()
SocialEventManagersSendEmail::executeMultiple in modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/SocialEventManagersSendEmail.php
Execute action on multiple entities.

File

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

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 = Settings::get('social_mail_chunk_size', 10);
  $chunks = array_chunk($objects, $chunk_size);
  $data = [];
  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;

    // Create the Queue Item.
    $this
      ->createQueueItem('user_email_queue', $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 [];
}