public function SocialEventAnEnrollSendEmail::executeMultiple in Open Social 10.0.x
Same name and namespace in other branches
- 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()
- 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()
- 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()
- 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()
- 10.2.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 119
Class
- SocialEventAnEnrollSendEmail
- Send email to event enrollment users.
Namespace
Drupal\social_event_an_enroll\Plugin\ActionCode
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.
$chunks = array_chunk($guests, 10);
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);
}