Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 11 additions & 1 deletion modules/os2forms_digital_post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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 +227,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,17 @@
$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;
$senderAddress = $context['senderAddress'] ?? '';

if (!$lookupResult instanceof CprLookupResult && !$lookupResult instanceof CompanyLookupResult) {
return;
}

if (!is_string($senderAddress)) {
$senderAddress = '';
}
Comment thread
jekuaitk marked this conversation as resolved.
Outdated

// Combine address parts.
$streetAddress = $lookupResult->getStreet();
Expand All @@ -52,7 +62,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>';
Comment thread
jekuaitk marked this conversation as resolved.
}
$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 +104,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 118 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 70 characters.'),
Comment thread
jekuaitk marked this conversation as resolved.
Outdated
'#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