You are here

public function SocialBulkGroupInvitation::submitForm in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_group/modules/social_group_invite/src/Form/SocialBulkGroupInvitation.php \Drupal\social_group_invite\Form\SocialBulkGroupInvitation::submitForm()
  2. 10.0.x modules/social_features/social_group/modules/social_group_invite/src/Form/SocialBulkGroupInvitation.php \Drupal\social_group_invite\Form\SocialBulkGroupInvitation::submitForm()
  3. 10.1.x modules/social_features/social_group/modules/social_group_invite/src/Form/SocialBulkGroupInvitation.php \Drupal\social_group_invite\Form\SocialBulkGroupInvitation::submitForm()
  4. 10.2.x modules/social_features/social_group/modules/social_group_invite/src/Form/SocialBulkGroupInvitation.php \Drupal\social_group_invite\Form\SocialBulkGroupInvitation::submitForm()

Custom form submit.

We override the source form submit, because we skip the confirm page to be consistent with inviting for events.

Throws

\Drupal\Core\TempStore\TempStoreException

File

modules/social_features/social_group/modules/social_group_invite/src/Form/SocialBulkGroupInvitation.php, line 343

Class

SocialBulkGroupInvitation
Class SocialBulkGroupInvitation.

Namespace

Drupal\social_group_invite\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Override the Batch created in BulkGroupInvitation
  // this so we can create a better message, use a new redirect in the
  // finished argument but also update the correct emails etc.
  $batch = [
    'title' => $this
      ->t('Inviting Members'),
    'operations' => [],
    'init_message' => $this
      ->t('Sending Invites'),
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
    'error_message' => $this
      ->t('An error occurred during processing'),
    'finished' => 'Drupal\\social_group_invite\\Form\\SocialBulkGroupInvitation::batchFinished',
  ];
  foreach ($form_state
    ->getValue('users_fieldset')['user'] as $email) {
    $email = $this
      ->extractEmailsFrom($email);

    // Make sure to only add valid emails to the batch.
    if ($email) {
      $values = [
        'type' => $this->group
          ->getGroupType()
          ->getContentPlugin('group_invitation')
          ->getContentTypeConfigId(),
        'gid' => $this->group
          ->id(),
        'invitee_mail' => $email,
        'entity_id' => 0,
      ];
      $batch['operations'][] = [
        '\\Drupal\\ginvite\\Form\\BulkGroupInvitationConfirm::batchCreateInvite',
        [
          $values,
        ],
      ];
    }
  }

  // Prepare params to store them in tempstore.
  $params = [];
  $params['gid'] = $this->group
    ->id();
  $params['plugin'] = $this->group
    ->getGroupType()
    ->getContentPlugin('group_invitation')
    ->getContentTypeConfigId();
  $params['emails'] = $this
    ->getSubmittedEmails($form_state);
  $tempstore = $this->tempStoreFactory
    ->get('ginvite_bulk_invitation');
  $tempstore
    ->set('params', $params);
  batch_set($batch);
}