Skip to content

Commit

Permalink
UHF-11127: Fix thrown error when user tries to get form with out uuid (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
jiisuominen committed Dec 12, 2024
1 parent 3e647d8 commit c7fd73c
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c7fd73c

Please sign in to comment.