Skip to content

Commit ed4c707

Browse files
committed
Added option to add sender address to digital post
1 parent 5fdc5d4 commit ed4c707

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1414
- [PR-301](https://github.com/OS2Forms/os2forms/pull/301)
1515
Add address information to Digital Post shipments to ensure "*fjernprint*"
1616
can be sent.
17+
- Add option to add sender (address) to Digital Post shipments.
1718

1819
## [5.0.0] 2025-11-18
1920

modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public function onPrintRender(PrintHtmlAlterEvent $event): void {
3131
$submission = $event->getEntities()[0];
3232
if ($submission instanceof WebformSubmissionInterface) {
3333
// Check whether generation is for digital post.
34-
if ($lookupResult = $this->getDigitalPostContext($submission)) {
34+
if ($context = $this->getDigitalPostContext($submission)) {
35+
$lookupResult = $context['lookupResult'];
36+
$senderAddress = $context['senderAddress'];
3537

3638
// Combine address parts.
3739
$streetAddress = $lookupResult->getStreet();
@@ -52,7 +54,11 @@ public function onPrintRender(PrintHtmlAlterEvent $event): void {
5254
}
5355

5456
// Generate address HTML.
55-
$addressHtml = '<div id="envelope-window-digital-post"><div class="h-card">';
57+
$addressHtml = '<div id="envelope-window-digital-post">';
58+
if (!empty($senderAddress)) {
59+
$addressHtml .= '<div id="sender-address-digital-post">' . htmlspecialchars($senderAddress) . '</div>';
60+
}
61+
$addressHtml .= '<div class="h-card">';
5662
$addressHtml .= '<div class="p-name">' . htmlspecialchars($lookupResult->getName()) . '</div>';
5763
if ($lookupResult instanceof CprLookupResult && $lookupResult->getCoName()) {
5864
$addressHtml .= '<div class="p-name p-co-name">c/o ' . htmlspecialchars($lookupResult->getCoName()) . '</div>';
@@ -90,15 +96,18 @@ public static function getSubscribedEvents(): array {
9096
/**
9197
* Indicate Digital Post context in the current session.
9298
*/
93-
public function setDigitalPostContext(WebformSubmissionInterface $submission, CompanyLookupResult|CprLookupResult $lookupResult): void {
99+
public function setDigitalPostContext(WebformSubmissionInterface $submission, CompanyLookupResult|CprLookupResult $lookupResult, string $senderAddress = ''): void {
94100
$key = $this->createSessionKeyFromSubmission($submission);
95-
$this->session->set($key, $lookupResult);
101+
$this->session->set($key, [
102+
'lookupResult' => $lookupResult,
103+
'senderAddress' => $senderAddress,
104+
]);
96105
}
97106

98107
/**
99108
* Check for Digital Post context in the current session.
100109
*/
101-
public function getDigitalPostContext(WebformSubmissionInterface $submission): CompanyLookupResult|CprLookupResult|null {
110+
public function getDigitalPostContext(WebformSubmissionInterface $submission): ?array {
102111
$key = $this->createSessionKeyFromSubmission($submission);
103112

104113
return $this->session->get($key);

modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ protected function getMainDocument(WebformSubmissionInterface $submission, array
6161
// @Drupal\entity_print\Renderer::generateHtml,
6262
// To indicate digital post context and get the necessary information,
6363
// we add a flag to the session.
64-
$this->digitalPostSubscriber->setDigitalPostContext($submission, $recipientData);
64+
$senderAddress = $handlerSettings[WebformHandlerSF1601::MEMO_MESSAGE][WebformHandlerSF1601::SENDER_ADDRESS] ?? '';
65+
$this->digitalPostSubscriber->setDigitalPostContext($submission, $recipientData, $senderAddress);
6566
$content = $instance::getFileContent($element, $submission);
6667
$this->digitalPostSubscriber->deleteDigitalPostContext($submission);
6768

modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ final class WebformHandlerSF1601 extends WebformHandlerBase {
3131
public const MESSAGE_HEADER_LABEL = 'message_header_label';
3232
public const RECIPIENT_ELEMENT = 'recipient_element';
3333
public const ATTACHMENT_ELEMENT = 'attachment_element';
34+
public const SENDER_ADDRESS = 'sender_address';
3435

3536
/**
3637
* Maximum length of sender label.
@@ -131,6 +132,14 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
131132
'#maxlength' => self::MESSAGE_HEADER_LABEL_MAX_LENGTH,
132133
];
133134

135+
$form[self::MEMO_MESSAGE][self::SENDER_ADDRESS] = [
136+
'#type' => 'textfield',
137+
'#title' => $this->t('Sender address'),
138+
'#description' => $this->t('Optional sender address shown on the printed document. Displayed as a single line above the recipient name.'),
139+
'#required' => FALSE,
140+
'#default_value' => $this->configuration[self::MEMO_MESSAGE][self::SENDER_ADDRESS] ?? NULL,
141+
];
142+
134143
$form[self::MEMO_ACTIONS] = [
135144
'#type' => 'fieldset',
136145
'#title' => $this->t('Actions'),

0 commit comments

Comments
 (0)