Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa

- Adding children information to Attachment SBSYS
- os2forms_webform_maps translation page fix
- [#369](https://github.com/OS2Forms/os2forms/pull/371) - Adding pnummber to Fasit handler

## [6.0.0] 2026-09-30

Expand Down
39 changes: 38 additions & 1 deletion modules/os2forms_fasit/os2forms_fasit.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @file
* Install hooks for os2forms_fasit.
* Install, update, and uninstall functions for OS2Forms Fasit.
*/

/**
Expand All @@ -13,3 +13,40 @@ function os2forms_fasit_update_9001(): void {
'key',
], TRUE);
}

/**
* Migrate existing Fasit handlers to primary party settings.
*/
function os2forms_fasit_update_10001(): void {
$config_factory = \Drupal::configFactory();

foreach ($config_factory->listAll('webform.webform.') as $config_name) {
$config = $config_factory->getEditable($config_name);
$handlers = $config->get('handlers') ?? [];
$changed = FALSE;

foreach ($handlers as &$handler) {
if (($handler['id'] ?? NULL) !== 'os2forms_fasit') {
continue;
}

$general = &$handler['settings']['general'];

if (isset($general['cpr_element']) && !isset($general['primary_party_element'])) {
$general['primary_party_element'] = $general['cpr_element'];
}
unset($general['cpr_element']);

if (!isset($general['primary_party_type'])) {
$general['primary_party_type'] = 'urn:schultz:dokument:1.0:primaerpart:cpr:';
}

$changed = TRUE;
}
unset($handler);

if ($changed) {
$config->set('handlers', $handlers)->save(TRUE);
}
}
}
24 changes: 12 additions & 12 deletions modules/os2forms_fasit/src/Helper/FasitHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
class FasitHelper {
private const FASIT_API_METHOD_UPLOAD = 'upload2';
private const FASIT_API_METHOD_CREATE = 'oio/3.0.0/opret';
private const FASIT_API_PRIMAERPART_TEMPLATE_VALUE = 'urn:schultz:dokument:1.0:primaerpart:cpr:';

/**
* File element types that may contain PDF files.
Expand Down Expand Up @@ -128,34 +127,35 @@ private function uploadDocument(array $uploads, string $submissionId, array $han
);

// Check handler configuration.
$this->checkHandlerConfiguration($handlerConfiguration, FasitWebformHandler::FASIT_HANDLER_CPR_ELEMENT);
$this->checkHandlerConfiguration($handlerConfiguration, FasitWebformHandler::FASIT_HANDLER_PRIMARY_PARTY_ELEMENT);
$this->checkHandlerConfiguration($handlerConfiguration, FasitWebformHandler::FASIT_HANDLER_DOCUMENT_TITLE);
$this->checkHandlerConfiguration($handlerConfiguration, FasitWebformHandler::FASIT_HANDLER_DOCUMENT_DESCRIPTION);

$fasitDocumentTitle = $handlerConfiguration[FasitWebformHandler::FASIT_HANDLER_GENERAL][FasitWebformHandler::FASIT_HANDLER_DOCUMENT_TITLE];
$fasitDocumentDescription = $handlerConfiguration[FasitWebformHandler::FASIT_HANDLER_GENERAL][FasitWebformHandler::FASIT_HANDLER_DOCUMENT_DESCRIPTION];
$fasitPrimaryPartyType = $handlerConfiguration[FasitWebformHandler::FASIT_HANDLER_GENERAL][FasitWebformHandler::FASIT_HANDLER_PRIMARY_PARTY_TYPE] ?? FasitWebformHandler::FASIT_PRIMARY_PARTY_CPR;

// Fasit CPR element.
$webformCprElementId = $handlerConfiguration[FasitWebformHandler::FASIT_HANDLER_GENERAL][FasitWebformHandler::FASIT_HANDLER_CPR_ELEMENT];
// Fasit primary party element.
$webformPrimaryPartyElementId = $handlerConfiguration[FasitWebformHandler::FASIT_HANDLER_GENERAL][FasitWebformHandler::FASIT_HANDLER_PRIMARY_PARTY_ELEMENT];

/** @var \Drupal\webform\Entity\WebformSubmission $submission */
$submission = $this->getSubmission($submissionId);
$submissionData = $submission->getData();

$fasitCpr = $submissionData[$webformCprElementId] ?? NULL;
$fasitPrimaryPartyIdentifier = $submissionData[$webformPrimaryPartyElementId] ?? NULL;

// Fix if os2forms_person_lookup (cpr & name validation) element is used.
if (is_array($fasitCpr)) {
// Extract the identifier if an os2forms_person_lookup element is used.
if (is_array($fasitPrimaryPartyIdentifier)) {
// Example:
// [
// 'cpr_number' => 1234567890,
// 'name' => Eksempel Eksempelsen,
// ].
$fasitCpr = $fasitCpr['cpr_number'] ?? NULL;
$fasitPrimaryPartyIdentifier = $fasitPrimaryPartyIdentifier['cpr_number'] ?? NULL;
}

if (NULL === $fasitCpr) {
throw new InvalidSubmissionException(sprintf('Could not determine value of configured CPR element in submission.'));
if (NULL === $fasitPrimaryPartyIdentifier) {
throw new InvalidSubmissionException('Could not determine the configured primary party identifier in submission.');
}

// Construct XML.
Expand Down Expand Up @@ -204,7 +204,7 @@ private function uploadDocument(array $uploads, string $submissionId, array $han
$referenceIdChildElements = $element->childNodes;
foreach ($referenceIdChildElements as $referenceIdChildElement) {
if ($referenceIdChildElement->nodeName === 'UUIDIdentifikator') {
$referenceIdChildElement->nodeValue = self::FASIT_API_PRIMAERPART_TEMPLATE_VALUE . $fasitCpr;
$referenceIdChildElement->nodeValue = $fasitPrimaryPartyType . $fasitPrimaryPartyIdentifier;
}
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ private function uploadDocument(array $uploads, string $submissionId, array $han
throw new FasitResponseException(sprintf('Expected status code 200, received %d', $response->getStatusCode()));
}

$msg = sprintf('Successfully uploaded document %s to cpr %s in Fasit. Webform id %s.', $fasitDocumentTitle, $fasitCpr, $submission->getWebform()->id());
$msg = sprintf('Successfully uploaded document %s to primary party %s in Fasit. Webform id %s.', $fasitDocumentTitle, $fasitPrimaryPartyIdentifier, $submission->getWebform()->id());
$this->auditLogger->info('Fasit', $msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class FasitWebformHandler extends WebformHandlerBase {
public const FASIT_HANDLER_GENERAL = 'general';
public const FASIT_HANDLER_DOCUMENT_TITLE = 'document_title';
public const FASIT_HANDLER_DOCUMENT_DESCRIPTION = 'document_description';
public const FASIT_HANDLER_CPR_ELEMENT = 'cpr_element';
public const FASIT_HANDLER_PRIMARY_PARTY_TYPE = 'primary_party_type';
public const FASIT_HANDLER_PRIMARY_PARTY_ELEMENT = 'primary_party_element';
public const FASIT_HANDLER_ATTACHMENT_ELEMENT = 'attachment_element';
public const FASIT_PRIMARY_PARTY_CPR = 'urn:schultz:dokument:1.0:primaerpart:cpr:';
public const FASIT_PRIMARY_PARTY_PNUMBER = 'urn:schultz:dokument:1.0:primaerpart:pnummer:';

/**
* The submission logger.
Expand Down Expand Up @@ -109,12 +112,24 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#required' => TRUE,
];

$form[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_CPR_ELEMENT] = [
$form[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_PRIMARY_PARTY_TYPE] = [
'#type' => 'select',
'#title' => $this->t('CPR element'),
'#title' => $this->t('Primary party type'),
'#options' => [
self::FASIT_PRIMARY_PARTY_CPR => $this->t('CPR'),
self::FASIT_PRIMARY_PARTY_PNUMBER => $this->t('PNUMMER'),
],
'#default_value' => $this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_PRIMARY_PARTY_TYPE] ?? self::FASIT_PRIMARY_PARTY_CPR,
'#description' => $this->t('Choose the type used when journaling the primary party in Fasit.'),
'#required' => TRUE,
];

$form[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_PRIMARY_PARTY_ELEMENT] = [
'#type' => 'select',
'#title' => $this->t('Primary party element'),
'#options' => $this->getAvailableElementsByType(['textfield', 'os2forms_nemid_cpr', 'os2forms_person_lookup'], $elements),
'#default_value' => $this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_CPR_ELEMENT] ?? '',
'#description' => $this->t('Choose element containing CPR.'),
'#default_value' => $this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_PRIMARY_PARTY_ELEMENT] ?? '',
'#description' => $this->t('Choose the element containing the primary party identifier.'),
'#required' => TRUE,
'#size' => 5,
];
Expand All @@ -141,7 +156,8 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
parent::submitConfigurationForm($form, $form_state);
$this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_DOCUMENT_TITLE] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_DOCUMENT_TITLE];
$this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_DOCUMENT_DESCRIPTION] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_DOCUMENT_DESCRIPTION];
$this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_CPR_ELEMENT] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_CPR_ELEMENT];
$this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_PRIMARY_PARTY_TYPE] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_PRIMARY_PARTY_TYPE];
$this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_PRIMARY_PARTY_ELEMENT] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_PRIMARY_PARTY_ELEMENT];
$this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_ATTACHMENT_ELEMENT] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_ATTACHMENT_ELEMENT];
}

Expand Down
Loading