You are here

public static function SocialEventInviteBulkHelper::bulkInviteUserEmailsFinished in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteBulkHelper.php \Drupal\social_event_invite\SocialEventInviteBulkHelper::bulkInviteUserEmailsFinished()
  2. 10.3.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteBulkHelper.php \Drupal\social_event_invite\SocialEventInviteBulkHelper::bulkInviteUserEmailsFinished()
  3. 10.0.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteBulkHelper.php \Drupal\social_event_invite\SocialEventInviteBulkHelper::bulkInviteUserEmailsFinished()
  4. 10.1.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteBulkHelper.php \Drupal\social_event_invite\SocialEventInviteBulkHelper::bulkInviteUserEmailsFinished()

Callback when the batch for inviting emails for an event has finished.

File

modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteBulkHelper.php, line 259

Class

SocialEventInviteBulkHelper
Class SocialEventBulkInvite.

Namespace

Drupal\social_event_invite

Code

public static function bulkInviteUserEmailsFinished($success, $results, $operations) {
  $nid = NULL;

  // We got the node event id in the results array so we will use that
  // to provide the param in in redirect url.
  if (!empty($results)) {

    // We don't care about resetting the array first.
    $nid = key($results);
  }
  if ($success && !empty($results)) {
    \Drupal::messenger()
      ->addStatus(t('Invite(s) have been successfully sent.'));
  }
  elseif ($success && empty($results)) {
    \Drupal::messenger()
      ->AddStatus(t('No invites were sent, recipients already received one before.'));
  }
  else {
    \Drupal::messenger()
      ->addError(t('There was an unexpected error.'));
  }

  // Redirect back to the event if we found the node ID.
  if ($nid) {
    return new RedirectResponse(Url::fromRoute('entity.node.canonical', [
      'node' => $nid,
    ])
      ->toString());
  }

  // If something went wrong, we have to redirect back to the frontpage.
  return new RedirectResponse(Url::fromRoute('<front>')
    ->toString());
}