From c7fd73cd6a72c5552ef65fce24ab415b6cc1c4a5 Mon Sep 17 00:00:00 2001 From: Janne Suominen Date: Thu, 12 Dec 2024 07:09:11 +0200 Subject: [PATCH] UHF-11127: Fix thrown error when user tries to get form with out uuid (#1606) * UHF-11127: Fix thrown error when user tries to get form with out uuid in metadata. * UHF-11127: Make sure the form_uuid is always set, even if it's not in the og metadata. --- .../src/ApplicationGetterService.php | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/public/modules/custom/grants_handler/src/ApplicationGetterService.php b/public/modules/custom/grants_handler/src/ApplicationGetterService.php index 0372e01b8..da3b97238 100644 --- a/public/modules/custom/grants_handler/src/ApplicationGetterService.php +++ b/public/modules/custom/grants_handler/src/ApplicationGetterService.php @@ -190,13 +190,22 @@ public function getCompanyApplications( } $submissionData = $submission->getData(); + $webform = $submission->getWebform(); + + // There's old applications w/o form_uuid, let's add it here + // Since we've already loaded webform for submission object the old way, + // we should have it here anyways. Just make sure it's in the metadata + // as well. + if (!isset($submissionData["metadata"]["form_uuid"])) { + $submissionData["metadata"]["form_uuid"] = $webform->uuid(); + } $submissionData['messages'] = $this->grantsHandlerMessageService->parseMessages($submissionData); $submission = [ '#theme' => $themeHook, '#submission' => $submissionData, '#document' => $document, - '#webform' => $submission->getWebform(), + '#webform' => $webform, '#submission_id' => $submission->id(), ]; @@ -260,6 +269,7 @@ public function getCompanyApplications( * * @throws \Drupal\Core\Entity\EntityStorageException * @throws \Drupal\grants_mandate\CompanySelectException + * @throws \Drupal\helfi_atv\AtvDocumentNotFoundException */ public function submissionObjectFromApplicationNumber( string $applicationNumber, @@ -377,11 +387,24 @@ public function getDataDefinition(string $type) { * * @return \Drupal\webform\Entity\Webform * Webform object. + * + * @throws \Drupal\helfi_atv\AtvDocumentNotFoundException */ public function getWebformFromApplicationNumber(string $applicationNumber): Webform { // We need the ATV document to get the form uuid. $document = $this->getAtvDocument($applicationNumber); - $uuid = $document->getMetadata()['form_uuid']; + + if (!$document) { + // No document, throw error. + throw new AtvDocumentNotFoundException('Document not found'); + } + + $uuid = $document->getMetadata()['form_uuid'] ?? NULL; + + if (!$uuid) { + // And return webform loaded the old way. + return ApplicationHelpers::getWebformFromApplicationNumber($applicationNumber); + } try { // Try to load webform via UUID and return it.