diff --git a/public/modules/custom/asu_application/src/Form/ApplicationForm.php b/public/modules/custom/asu_application/src/Form/ApplicationForm.php index b43ff1631..a394ff6d0 100644 --- a/public/modules/custom/asu_application/src/Form/ApplicationForm.php +++ b/public/modules/custom/asu_application/src/Form/ApplicationForm.php @@ -534,6 +534,8 @@ public function save(array $form, FormStateInterface $form_state) { /** * Handle saving the form values. * + * Deletes old application. + * * @param array $form * Form array. * @param \Drupal\Core\Form\FormStateInterface $form_state @@ -548,7 +550,12 @@ private function doSave(array $form, FormStateInterface $form_state, $errors = T $oldBackendId = $this->entity->get('field_backend_id')->value ?? NULL; $confirmDeletion = $form_state->getValue('confirm_application_deletion') ?? 'NOT SET'; - if ($oldBackendId && $confirmDeletion == '1') { + $project_id = $this->entity->get('project_id')->value; + $project = $this->entityTypeManager->getStorage('node')->load($project_id); + $canApplyAfterwards = $project->get('field_can_apply_afterwards')->value; + + // Applications made after shouldn't be deleted. + if ($oldBackendId && $confirmDeletion == '1' && !$canApplyAfterwards) { try { $user = \Drupal::entityTypeManager()->getStorage('user')->load(\Drupal::currentUser()->id()); \Drupal::service('asu_api.backendapi')->deleteApplication($user, $oldBackendId);