Skip to content

Commit 381f438

Browse files
committed
Added max length for sender and checks for context being correctly set
1 parent 8fbeeaa commit 381f438

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

modules/os2forms_digital_post/src/EventSubscriber/Os2formsDigitalPostSubscriber.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ public function onPrintRender(PrintHtmlAlterEvent $event): void {
3232
if ($submission instanceof WebformSubmissionInterface) {
3333
// Check whether generation is for digital post.
3434
if ($context = $this->getDigitalPostContext($submission)) {
35-
$lookupResult = $context['lookupResult'];
36-
$senderAddress = $context['senderAddress'];
35+
$lookupResult = $context['lookupResult'] ?? NULL;
36+
$senderAddress = $context['senderAddress'] ?? '';
37+
38+
if (!$lookupResult instanceof CprLookupResult && !$lookupResult instanceof CompanyLookupResult) {
39+
return;
40+
}
41+
42+
if (!is_string($senderAddress)) {
43+
$senderAddress = '';
44+
}
3745

3846
// Combine address parts.
3947
$streetAddress = $lookupResult->getStreet();

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ final class WebformHandlerSF1601 extends WebformHandlerBase {
3838
*/
3939
private const SENDER_LABEL_MAX_LENGTH = 64;
4040

41+
/**
42+
* Maximum length of sender address.
43+
*/
44+
private const SENDER_ADDRESS_MAX_LENGTH = 70;
45+
4146
/**
4247
* Maximum length of header label.
4348
*/
@@ -135,9 +140,10 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
135140
$form[self::MEMO_MESSAGE][self::SENDER_ADDRESS] = [
136141
'#type' => 'textfield',
137142
'#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.'),
143+
'#description' => $this->t('Optional sender address shown on the printed document. Displayed as a single line above the recipient name. Maximum 70 characters.'),
139144
'#required' => FALSE,
140145
'#default_value' => $this->configuration[self::MEMO_MESSAGE][self::SENDER_ADDRESS] ?? NULL,
146+
'#maxlength' => self::SENDER_ADDRESS_MAX_LENGTH,
141147
];
142148

143149
$form[self::MEMO_ACTIONS] = [

0 commit comments

Comments
 (0)