diff --git a/CHANGELOG.md b/CHANGELOG.md index 200bbc16..ff58d468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [PR-301](https://github.com/OS2Forms/os2forms/pull/301) Add address information to Digital Post shipments to ensure "*fjernprint*" can be sent. +- Add option to add return address to Digital Post shipments. ## [5.0.0] 2025-11-18 diff --git a/modules/os2forms_digital_post/README.md b/modules/os2forms_digital_post/README.md index a8f5f638..471bd6e6 100644 --- a/modules/os2forms_digital_post/README.md +++ b/modules/os2forms_digital_post/README.md @@ -96,17 +96,23 @@ also means that it is up to individual installations to style it correctly. This should be done in OS2Forms Attachment-templates, see [Overwriting templates](https://github.com/OS2Forms/os2forms/tree/develop/modules/os2forms_attachment#overwriting-templates). -To see the exact requirements for address placement, see +Furthermore, a single-line sender address may be configured on the handler. +The value of this field will be injected into the HTML as a sender address, +which should be placed within the envelope window just above the recipient +address. As with the recipient information, it is up to individual +installations to style it correctly. + +To see the exact requirements for address and sender placement, see [digst_a4_farve_ej_til_kant_demo_ny_rudeplacering.pdf](docs/digst_a4_farve_ej_til_kant_demo_ny_rudeplacering.pdf). ### The injected HTML -Variations of the injected HTML include extended addresses and c/o. +Variations of the injected HTML include extended addresses, c/o and sender +address. -Without extended address information or c/o: +Without extended address information, c/o or sender address: ```html -
Jeppe
@@ -131,7 +137,6 @@ With just an extended address: With just c/o: ```html -
Jeppe
@@ -141,10 +146,25 @@ With just c/o:
``` -With extended address information and c/o: +With just the sender address: ```html
+
Dokk1, Hack Kampmanns Plads 2, 8000 Aarhus C
+
+
Jeppe
+
Test vej HouseNr
+
2100 Copenhagen
+
+
+``` + + +With extended address information, c/o and sender address: + +```html +
+
Dokk1, Hack Kampmanns Plads 2, 8000 Aarhus C
Jeppe
c/o Mikkel
@@ -218,7 +238,7 @@ footer { } // Style the h-card div -#envelope-window-digital-post > div { +#envelope-window-digital-post > .h-card { position: absolute; top: 16mm; left: 4mm; @@ -227,5 +247,15 @@ footer { width: $recipient-window-width; } +// Style the sender address div +#envelope-window-digital-post > #sender-address-digital-post { + position: absolute; + top: 12mm; + left: 4mm; + font-size: 8px; + height: 4mm; + width: 71mm; +} + // More custom styling... ``` diff --git a/modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php b/modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php index e0677a38..e4b686bb 100644 --- a/modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php +++ b/modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php @@ -31,7 +31,16 @@ public function onPrintRender(PrintHtmlAlterEvent $event): void { $submission = $event->getEntities()[0]; if ($submission instanceof WebformSubmissionInterface) { // Check whether generation is for digital post. - if ($lookupResult = $this->getDigitalPostContext($submission)) { + if ($context = $this->getDigitalPostContext($submission)) { + $lookupResult = $context['lookupResult'] ?? NULL; + if (!$lookupResult instanceof CprLookupResult && !$lookupResult instanceof CompanyLookupResult) { + return; + } + + $senderAddress = $context['senderAddress'] ?? ''; + if (!is_string($senderAddress)) { + $senderAddress = ''; + } // Combine address parts. $streetAddress = $lookupResult->getStreet(); @@ -52,7 +61,11 @@ public function onPrintRender(PrintHtmlAlterEvent $event): void { } // Generate address HTML. - $addressHtml = '
'; + $addressHtml = '
'; + if (!empty($senderAddress)) { + $addressHtml .= '
' . htmlspecialchars($senderAddress) . '
'; + } + $addressHtml .= '
'; $addressHtml .= '
' . htmlspecialchars($lookupResult->getName()) . '
'; if ($lookupResult instanceof CprLookupResult && $lookupResult->getCoName()) { $addressHtml .= '
c/o ' . htmlspecialchars($lookupResult->getCoName()) . '
'; @@ -90,15 +103,18 @@ public static function getSubscribedEvents(): array { /** * Indicate Digital Post context in the current session. */ - public function setDigitalPostContext(WebformSubmissionInterface $submission, CompanyLookupResult|CprLookupResult $lookupResult): void { + public function setDigitalPostContext(WebformSubmissionInterface $submission, CompanyLookupResult|CprLookupResult $lookupResult, string $senderAddress = ''): void { $key = $this->createSessionKeyFromSubmission($submission); - $this->session->set($key, $lookupResult); + $this->session->set($key, [ + 'lookupResult' => $lookupResult, + 'senderAddress' => $senderAddress, + ]); } /** * Check for Digital Post context in the current session. */ - public function getDigitalPostContext(WebformSubmissionInterface $submission): CompanyLookupResult|CprLookupResult|null { + public function getDigitalPostContext(WebformSubmissionInterface $submission): ?array { $key = $this->createSessionKeyFromSubmission($submission); return $this->session->get($key); diff --git a/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php b/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php index 0746f20e..368ac1ac 100644 --- a/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php +++ b/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php @@ -61,7 +61,8 @@ protected function getMainDocument(WebformSubmissionInterface $submission, array // @Drupal\entity_print\Renderer::generateHtml, // To indicate digital post context and get the necessary information, // we add a flag to the session. - $this->digitalPostSubscriber->setDigitalPostContext($submission, $recipientData); + $senderAddress = $handlerSettings[WebformHandlerSF1601::MEMO_MESSAGE][WebformHandlerSF1601::SENDER_ADDRESS] ?? ''; + $this->digitalPostSubscriber->setDigitalPostContext($submission, $recipientData, $senderAddress); $content = $instance::getFileContent($element, $submission); $this->digitalPostSubscriber->deleteDigitalPostContext($submission); diff --git a/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php b/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php index 0b1dc219..6f0e06a9 100644 --- a/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php +++ b/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php @@ -31,12 +31,18 @@ final class WebformHandlerSF1601 extends WebformHandlerBase { public const MESSAGE_HEADER_LABEL = 'message_header_label'; public const RECIPIENT_ELEMENT = 'recipient_element'; public const ATTACHMENT_ELEMENT = 'attachment_element'; + public const SENDER_ADDRESS = 'sender_address'; /** * Maximum length of sender label. */ private const SENDER_LABEL_MAX_LENGTH = 64; + /** + * Maximum length of sender address. + */ + private const SENDER_ADDRESS_MAX_LENGTH = 70; + /** * Maximum length of header label. */ @@ -131,6 +137,15 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat '#maxlength' => self::MESSAGE_HEADER_LABEL_MAX_LENGTH, ]; + $form[self::MEMO_MESSAGE][self::SENDER_ADDRESS] = [ + '#type' => 'textfield', + '#title' => $this->t('Sender address'), + '#description' => $this->t('Optional sender address shown on the printed document. Displayed as a single line above the recipient name. Maximum @max characters.', ['@max' => self::SENDER_ADDRESS_MAX_LENGTH]), + '#required' => FALSE, + '#default_value' => $this->configuration[self::MEMO_MESSAGE][self::SENDER_ADDRESS] ?? NULL, + '#maxlength' => self::SENDER_ADDRESS_MAX_LENGTH, + ]; + $form[self::MEMO_ACTIONS] = [ '#type' => 'fieldset', '#title' => $this->t('Actions'),