Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-11127: Fix thrown error when user tries to get form with out uuid #1606

Merged
merged 2 commits into from
Dec 12, 2024
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 @@ -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
Loading