Skip to content

Commit

Permalink
fix: UHF-10142: Allow "Delete" button to show on RECEIVED application…
Browse files Browse the repository at this point in the history
…s when navigating on the form. (#1510)

* UHF-10142: Add condition for received applications to allow removal of the recently added attachment.

* UHF-10142: Fix comment
  • Loading branch information
jiisuominen authored Oct 21, 2024
1 parent aee4e03 commit e2d0d51
Showing 1 changed file with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public static function processWebformComposite(&$element, FormStateInterface $fo
// When user goes to previous step etc. we might lose the additional data for the just
// uploaded elements. As we are saving these to storage - let's find
// out the actual data the and use it.

if ($dataForElement['integrationID'] && isset($storage['fids_info']) && $dataForElement) {
foreach ($storage['fids_info'] as $finfo) {
if ($dataForElement['integrationID'] == $finfo['integrationID']) {
Expand Down Expand Up @@ -168,30 +167,48 @@ public static function processWebformComposite(&$element, FormStateInterface $fo
$element["description"]["#attributes"] = ['readonly' => 'readonly'];
}

/** @var \Drupal\grants_handler\ApplicationStatusService $applicationStatusService */
$applicationStatusService = \Drupal::service('grants_handler.application_status_service');

if (
isset($dataForElement['fileType'])
&& $dataForElement['fileType'] != '45'
&& (isset($submissionData['status']) && $submissionData['status'] === 'DRAFT')
&& $applicationStatusService->isSubmissionEditable($submission)
) {
$element['deleteItem'] = [
'#type' => 'submit',
'#name' => 'delete_' . $arrayKey,
'#value' => t('Delete attachment', [], $tOpts),
'#submit' => [
[
'\Drupal\grants_attachments\Element\GrantsAttachments',
'deleteAttachmentSubmit',
// By default we allow deletion of the attachment if submission is
// editable AND the file type is not 45 (account confirmation).
$showDeleteButton = TRUE;

// But since the attachments currently work differently than the other
// fields regarding to editing, we need to do additional check for
// explicitly application status and upload status.
if ($submissionData['status'] === 'RECEIVED' && $uploadStatus !== 'justUploaded') {
// We allow deletion of the attachment only if it has been just
// uploaded. Just meaning this editing session.
$showDeleteButton = FALSE;
}

if ($showDeleteButton === TRUE) {
$element['deleteItem'] = [
'#type' => 'submit',
'#name' => 'delete_' . $arrayKey,
'#value' => t('Delete attachment', [], $tOpts),
'#submit' => [
[
'\Drupal\grants_attachments\Element\GrantsAttachments',
'deleteAttachmentSubmit',
],
],
],
'#limit_validation_errors' => [[$element['#webform_key']]],
'#ajax' => [
'callback' => [
'\Drupal\grants_attachments\Element\GrantsAttachments',
'deleteAttachment',
'#limit_validation_errors' => [[$element['#webform_key']]],
'#ajax' => [
'callback' => [
'\Drupal\grants_attachments\Element\GrantsAttachments',
'deleteAttachment',
],
'wrapper' => $element["#webform_id"],
],
'wrapper' => $element["#webform_id"],
],
];
];
}
}
}
if (isset($dataForElement['description'])) {
Expand Down

0 comments on commit e2d0d51

Please sign in to comment.