Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down