You are here

public function SocialEventManagersAddEnrolleeForm::submitForm in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  2. 8.6 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  3. 8.7 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  4. 8.8 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  5. 10.3.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  6. 10.0.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  7. 10.1.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::submitForm()
  8. 10.2.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::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 FormInterface::submitForm

File

modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php, line 71

Class

SocialEventManagersAddEnrolleeForm
Class SocialEventTypeSettings.

Namespace

Drupal\social_event_managers\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $enroll_uid = $form_state
    ->getValue('entity_id_new');
  $event = $form_state
    ->getValue('node_id');
  $count = 0;
  if (!empty($event) && !empty($enroll_uid)) {

    // Create a new enrollment for the event.
    foreach ($enroll_uid as $uid => $target_id) {
      $enrollment = EventEnrollment::create([
        'user_id' => \Drupal::currentUser()
          ->id(),
        'field_event' => $event,
        'field_enrollment_status' => '1',
        'field_account' => $uid,
      ]);
      $enrollment
        ->save();
      $count++;
    }

    // Add nice messages.
    if (!empty($count)) {
      $singular = '@count new member is enrolled to this event.';
      $plural = '@count new members are enrolled to this event.';
      if (social_event_manager_or_organizer(NULL, TRUE)) {
        $singular = '@count new member is enrolled to your event.';
        $plural = '@count new members are enrolled to your event.';
      }
      $message = $this
        ->formatPlural($count, $singular, $plural);
      \Drupal::messenger()
        ->addMessage($message, 'status');
    }

    // Redirect to management overview.
    $url = Url::fromRoute('view.event_manage_enrollments.page_manage_enrollments', [
      'node' => $event,
    ]);
    $form_state
      ->setRedirectUrl($url);
  }
}