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 @@ -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 sender (address) to Digital Post shipments.

## [5.0.0] 2025-11-18

Expand Down
44 changes: 37 additions & 7 deletions modules/os2forms_digital_post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<div id="envelope-window-digital-post">
<div class="h-card">
<div class="p-name">Jeppe</div>
Expand All @@ -131,7 +137,6 @@ With just an extended address:
With just c/o:

```html

<div id="envelope-window-digital-post">
<div class="h-card">
<div class="p-name">Jeppe</div>
Expand All @@ -141,10 +146,25 @@ With just c/o:
</div>
```

With extended address information and c/o:
With just the sender address:

```html
<div id="envelope-window-digital-post">
<div id="sender-address-digital-post">Dokk1, Hack Kampmanns Plads 2, 8000 Aarhus C</div>
<div class="h-card">
<div class="p-name">Jeppe</div>
<div><span class="p-street-address">Test vej HouseNr</span></div>
<div><span class="p-postal-code">2100</span> <span class="p-locality">Copenhagen</span></div>
</div>
</div>
```


With extended address information, c/o and sender address:

```html
<div id="envelope-window-digital-post">
<div id="sender-address-digital-post">Dokk1, Hack Kampmanns Plads 2, 8000 Aarhus C</div>
<div class="h-card">
<div class="p-name">Jeppe</div>
<div class="p-name">c/o Mikkel</div>
Expand Down Expand Up @@ -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;
Expand All @@ -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...
```
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
$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();
Expand All @@ -52,7 +61,11 @@
}

// Generate address HTML.
$addressHtml = '<div id="envelope-window-digital-post"><div class="h-card">';
$addressHtml = '<div id="envelope-window-digital-post">';
if (!empty($senderAddress)) {
$addressHtml .= '<div id="sender-address-digital-post">' . htmlspecialchars($senderAddress) . '</div>';
}
$addressHtml .= '<div class="h-card">';
$addressHtml .= '<div class="p-name">' . htmlspecialchars($lookupResult->getName()) . '</div>';
if ($lookupResult instanceof CprLookupResult && $lookupResult->getCoName()) {
$addressHtml .= '<div class="p-name p-co-name">c/o ' . htmlspecialchars($lookupResult->getCoName()) . '</div>';
Expand Down Expand Up @@ -90,15 +103,18 @@
/**
* 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 {

Check failure on line 117 in modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php

View workflow job for this annotation

GitHub Actions / PHP code analysis

Method Drupal\os2forms_digital_post\EventSubscriber\Os2formsDigitalPostSubscriber::getDigitalPostContext() return type has no value type specified in iterable type array.
$key = $this->createSessionKeyFromSubmission($submission);

return $this->session->get($key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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'),
Expand Down
Loading