Skip to content

Commit fc3d2c4

Browse files
authored
Merge pull request #13 from itk-dev/feature/sender-address-in-digital-post
Feature/sender address in digital post
2 parents 5fdc5d4 + e0794f6 commit fc3d2c4

5 files changed

Lines changed: 76 additions & 13 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 return address to Digital Post shipments.
1718

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

modules/os2forms_digital_post/README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,23 @@ also means that it is up to individual installations to style it correctly.
9696
This should be done in OS2Forms Attachment-templates, see
9797
[Overwriting templates](https://github.com/OS2Forms/os2forms/tree/develop/modules/os2forms_attachment#overwriting-templates).
9898

99-
To see the exact requirements for address placement, see
99+
Furthermore, a single-line sender address may be configured on the handler.
100+
The value of this field will be injected into the HTML as a sender address,
101+
which should be placed within the envelope window just above the recipient
102+
address. As with the recipient information, it is up to individual
103+
installations to style it correctly.
104+
105+
To see the exact requirements for address and sender placement, see
100106
[digst_a4_farve_ej_til_kant_demo_ny_rudeplacering.pdf](docs/digst_a4_farve_ej_til_kant_demo_ny_rudeplacering.pdf).
101107

102108
### The injected HTML
103109

104-
Variations of the injected HTML include extended addresses and c/o.
110+
Variations of the injected HTML include extended addresses, c/o and sender
111+
address.
105112

106-
Without extended address information or c/o:
113+
Without extended address information, c/o or sender address:
107114

108115
```html
109-
110116
<div id="envelope-window-digital-post">
111117
<div class="h-card">
112118
<div class="p-name">Jeppe</div>
@@ -131,7 +137,6 @@ With just an extended address:
131137
With just c/o:
132138

133139
```html
134-
135140
<div id="envelope-window-digital-post">
136141
<div class="h-card">
137142
<div class="p-name">Jeppe</div>
@@ -141,10 +146,25 @@ With just c/o:
141146
</div>
142147
```
143148

144-
With extended address information and c/o:
149+
With just the sender address:
145150

146151
```html
147152
<div id="envelope-window-digital-post">
153+
<div id="sender-address-digital-post">Dokk1, Hack Kampmanns Plads 2, 8000 Aarhus C</div>
154+
<div class="h-card">
155+
<div class="p-name">Jeppe</div>
156+
<div><span class="p-street-address">Test vej HouseNr</span></div>
157+
<div><span class="p-postal-code">2100</span> <span class="p-locality">Copenhagen</span></div>
158+
</div>
159+
</div>
160+
```
161+
162+
163+
With extended address information, c/o and sender address:
164+
165+
```html
166+
<div id="envelope-window-digital-post">
167+
<div id="sender-address-digital-post">Dokk1, Hack Kampmanns Plads 2, 8000 Aarhus C</div>
148168
<div class="h-card">
149169
<div class="p-name">Jeppe</div>
150170
<div class="p-name">c/o Mikkel</div>
@@ -218,7 +238,7 @@ footer {
218238
}
219239

220240
// Style the h-card div
221-
#envelope-window-digital-post > div {
241+
#envelope-window-digital-post > .h-card {
222242
position: absolute;
223243
top: 16mm;
224244
left: 4mm;
@@ -227,5 +247,15 @@ footer {
227247
width: $recipient-window-width;
228248
}
229249

250+
// Style the sender address div
251+
#envelope-window-digital-post > #sender-address-digital-post {
252+
position: absolute;
253+
top: 12mm;
254+
left: 4mm;
255+
font-size: 8px;
256+
height: 4mm;
257+
width: 71mm;
258+
}
259+
230260
// More custom styling...
231261
```

modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ 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'] ?? NULL;
36+
if (!$lookupResult instanceof CprLookupResult && !$lookupResult instanceof CompanyLookupResult) {
37+
return;
38+
}
39+
40+
$senderAddress = $context['senderAddress'] ?? '';
41+
if (!is_string($senderAddress)) {
42+
$senderAddress = '';
43+
}
3544

3645
// Combine address parts.
3746
$streetAddress = $lookupResult->getStreet();
@@ -52,7 +61,11 @@ public function onPrintRender(PrintHtmlAlterEvent $event): void {
5261
}
5362

5463
// Generate address HTML.
55-
$addressHtml = '<div id="envelope-window-digital-post"><div class="h-card">';
64+
$addressHtml = '<div id="envelope-window-digital-post">';
65+
if (!empty($senderAddress)) {
66+
$addressHtml .= '<div id="sender-address-digital-post">' . htmlspecialchars($senderAddress) . '</div>';
67+
}
68+
$addressHtml .= '<div class="h-card">';
5669
$addressHtml .= '<div class="p-name">' . htmlspecialchars($lookupResult->getName()) . '</div>';
5770
if ($lookupResult instanceof CprLookupResult && $lookupResult->getCoName()) {
5871
$addressHtml .= '<div class="p-name p-co-name">c/o ' . htmlspecialchars($lookupResult->getCoName()) . '</div>';
@@ -90,15 +103,18 @@ public static function getSubscribedEvents(): array {
90103
/**
91104
* Indicate Digital Post context in the current session.
92105
*/
93-
public function setDigitalPostContext(WebformSubmissionInterface $submission, CompanyLookupResult|CprLookupResult $lookupResult): void {
106+
public function setDigitalPostContext(WebformSubmissionInterface $submission, CompanyLookupResult|CprLookupResult $lookupResult, string $senderAddress = ''): void {
94107
$key = $this->createSessionKeyFromSubmission($submission);
95-
$this->session->set($key, $lookupResult);
108+
$this->session->set($key, [
109+
'lookupResult' => $lookupResult,
110+
'senderAddress' => $senderAddress,
111+
]);
96112
}
97113

98114
/**
99115
* Check for Digital Post context in the current session.
100116
*/
101-
public function getDigitalPostContext(WebformSubmissionInterface $submission): CompanyLookupResult|CprLookupResult|null {
117+
public function getDigitalPostContext(WebformSubmissionInterface $submission): ?array {
102118
$key = $this->createSessionKeyFromSubmission($submission);
103119

104120
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ 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.
3738
*/
3839
private const SENDER_LABEL_MAX_LENGTH = 64;
3940

41+
/**
42+
* Maximum length of sender address.
43+
*/
44+
private const SENDER_ADDRESS_MAX_LENGTH = 70;
45+
4046
/**
4147
* Maximum length of header label.
4248
*/
@@ -131,6 +137,15 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
131137
'#maxlength' => self::MESSAGE_HEADER_LABEL_MAX_LENGTH,
132138
];
133139

140+
$form[self::MEMO_MESSAGE][self::SENDER_ADDRESS] = [
141+
'#type' => 'textfield',
142+
'#title' => $this->t('Sender address'),
143+
'#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]),
144+
'#required' => FALSE,
145+
'#default_value' => $this->configuration[self::MEMO_MESSAGE][self::SENDER_ADDRESS] ?? NULL,
146+
'#maxlength' => self::SENDER_ADDRESS_MAX_LENGTH,
147+
];
148+
134149
$form[self::MEMO_ACTIONS] = [
135150
'#type' => 'fieldset',
136151
'#title' => $this->t('Actions'),

0 commit comments

Comments
 (0)