public function EventInviteEnrollActionForm::submitForm in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm::submitForm()
- 10.0.x modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm::submitForm()
- 10.1.x modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm::submitForm()
- 10.2.x modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm::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 EnrollActionForm::submitForm
File
- modules/
social_features/ social_event/ modules/ social_event_invite/ src/ Form/ EventInviteEnrollActionForm.php, line 143
Class
- EventInviteEnrollActionForm
- Class EventInviteEnrollActionForm.
Namespace
Drupal\social_event_invite\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$operation = $form_state
->getValue('operation');
$current_user = $this->currentUser;
$uid = $current_user
->id();
$nid = $form_state
->getValue('event') ?? $this->routeMatch
->getRawParameter('node');
$conditions = [
'field_account' => $uid,
'field_event' => $nid,
];
$enrollments = $this->entityStorage
->loadByProperties($conditions);
// @todo also clear the breadcrumb cachetags.
// Invalidate cache for our enrollment cache tag in
// social_event_node_view_alter().
$tags = [];
$tags[] = 'enrollment:' . $nid . '-' . $uid;
$tags[] = 'event_content_list:entity:' . $uid;
Cache::invalidateTags($tags);
if ($enrollment = array_pop($enrollments)) {
// Only trigger when the user is invited.
if ($enrollment->field_request_or_invite_status && (int) $enrollment->field_request_or_invite_status->value === EventEnrollmentInterface::INVITE_PENDING_REPLY) {
// Delete any messages since it would show a 'successful enrollment'.
$this
->messenger()
->deleteAll();
// Accept the invite.
$enrollment->field_enrollment_status->value = '1';
$enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::INVITE_ACCEPTED_AND_JOINED;
// If decline is chosen, set invite to declined.
if ($operation === 'decline') {
// Delete any messages since it would show a 'successful enrollment'.
$this
->messenger()
->deleteAll();
$enrollment->field_enrollment_status->value = '0';
$enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED;
}
$enrollment
->save();
}
}
}