You are here

public function EnrollInviteEmailForm::submitForm 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/Form/EnrollInviteEmailForm.php \Drupal\social_event_invite\Form\EnrollInviteEmailForm::submitForm()
  2. 10.3.x modules/social_features/social_event/modules/social_event_invite/src/Form/EnrollInviteEmailForm.php \Drupal\social_event_invite\Form\EnrollInviteEmailForm::submitForm()
  3. 10.0.x modules/social_features/social_event/modules/social_event_invite/src/Form/EnrollInviteEmailForm.php \Drupal\social_event_invite\Form\EnrollInviteEmailForm::submitForm()
  4. 10.1.x modules/social_features/social_event/modules/social_event_invite/src/Form/EnrollInviteEmailForm.php \Drupal\social_event_invite\Form\EnrollInviteEmailForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides InviteEmailBaseForm::submitForm

File

modules/social_features/social_event/modules/social_event_invite/src/Form/EnrollInviteEmailForm.php, line 238

Class

EnrollInviteEmailForm
Class EnrollInviteForm.

Namespace

Drupal\social_event_invite\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $params['recipients'] = $form_state
    ->getValue('users_fieldset')['user'];
  $params['nid'] = $form_state
    ->getValue('event');
  $tempstore = $this->tempStoreFactory
    ->get('event_invite_form_values');
  try {
    $tempstore
      ->set('params', $params);

    // Create batch for sending out the invites.
    $batch = [
      'title' => $this
        ->t('Sending invites...'),
      'init_message' => $this
        ->t("Preparing to send invites..."),
      'operations' => [
        [
          '\\Drupal\\social_event_invite\\SocialEventInviteBulkHelper::bulkInviteUsersEmails',
          [
            $params['recipients'],
            $params['nid'],
          ],
        ],
      ],
      'finished' => '\\Drupal\\social_event_invite\\SocialEventInviteBulkHelper::bulkInviteUserEmailsFinished',
    ];
    batch_set($batch);
  } catch (\Exception $error) {
    $this->loggerFactory
      ->get('event_invite_form_values')
      ->alert(t('@err', [
      '@err' => $error,
    ]));
    $this->messenger
      ->addWarning(t('Unable to proceed, please try again.'));
  }
}