Skip to content

Commit e826f03

Browse files
committed
Cleaned up
1 parent 44faf4f commit e826f03

8 files changed

Lines changed: 89 additions & 32 deletions

File tree

modules/os2forms_fordelingskomponent_examples/config/install/webform.webform.os2forms_fdk_example_000.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ handlers:
277277
conditions: {}
278278
weight: 0
279279
settings:
280-
kle_emne: 01.01.01
281-
handling_facet: ""
282-
attachment_element: digital_post_content_pdf
280+
sf2900:
281+
kle_emne: 01.01.01
282+
handling_facet: G87
283+
attachment_element: afsend_content_pdf
284+
brugervendt_noegle: "What is “Brugervendt nøgle”?"
285+
titel: "Your document"
286+
beskrivelse: "This is a very important document"
283287
variants: {}

modules/os2forms_fordelingskomponent_examples/config/install/webform.webform.os2forms_fdk_example_001.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ handlers:
277277
conditions: {}
278278
weight: 0
279279
settings:
280-
kle_emne: 01.01.01
281-
handling_facet: ""
282-
attachment_element: digital_post_content_pdf
280+
sf2900:
281+
kle_emne: 01.01.01
282+
handling_facet: G87
283+
attachment_element: afsend_content_pdf
284+
brugervendt_noegle: "What is “Brugervendt nøgle”?"
285+
titel: "Your document"
286+
beskrivelse: "This is a very important document"
283287
variants: {}

os2forms_fordelingskomponent.routing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
os2forms_fordelingskomponent.settings:
1+
os2forms_fordelingskomponent.admin.settings:
22
path: "/admin/os2forms_fordelingskomponent/settings"
33
defaults:
44
_title: "Fordelingskomponent settings"

scripts/compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ services:
1919
# Let the module path, i.e. the mounted path, be known in the container
2020
MODULE_PATH: web/modules/contrib/$MODULE_NAME
2121
# https://getcomposer.org/doc/03-cli.md#composer-ignore-platform-req-or-composer-ignore-platform-reqs
22-
COMPOSER_IGNORE_PLATFORM_REQ: ext-soap,ext-xsl
2322
COMPOSER_IGNORE_PLATFORM_REQS: 1

src/Controller/Os2formsFordelingskomponentRoutingInfoController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ public function __invoke(WebformInterface $webform, string $handler): array {
3939
throw new NotFoundHttpException();
4040
}
4141

42-
$settings = $this->helper->getHandlerConfiguration($handler->getConfiguration());
42+
$settings = $this->helper->getHandlerConfiguration($handler);
4343
$info = $this->helper->getRoutingInfo(
4444
routingMyndighed: $settings[FordelingskomponentHelper::ROUTING_MYNDIGHED],
4545
kleEmne: $settings[FordelingskomponentHelper::KLE_EMNE],
4646
handlingFacet: $settings[FordelingskomponentHelper::HANDLING_FACET] ?: NULL,
4747
);
48+
4849
return [
4950
'stuff' => [
5051
'#prefix' => '<pre>',

src/Helper/FordelingskomponentHelper.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\key\KeyRepositoryInterface;
99
use Drupal\os2forms_fordelingskomponent\Form\SettingsForm;
1010
use Drupal\os2forms_fordelingskomponent\Model\Attachment;
11+
use Drupal\os2forms_fordelingskomponent\Plugin\WebformHandler\WebformHandlerSF2900;
1112
use Drupal\os2web_audit\Service\Logger as AuditLogger;
1213
use Drupal\os2web_key\KeyHelper;
1314
use Drupal\webform\WebformSubmissionInterface;
@@ -51,6 +52,9 @@ final class FordelingskomponentHelper implements LoggerInterface {
5152
public const string HANDLING_FACET = 'handling_facet';
5253
public const string KLE_EMNE_PATTERN = '^[0-9]{2}\.[0-9]{2}\.[0-9]{2}$';
5354
public const string HANDLING_FACET_PATTERN = '^[A-Z,Æ,Ø,Å][0-9][0-9]$';
55+
public const string TITEL = 'titel';
56+
public const string BESKRIVELSE = 'beskrivelse';
57+
public const string BRUGERVENDT_NOEGLE = 'brugervendt_noegle';
5458

5559
/**
5660
* Constructor.
@@ -143,7 +147,7 @@ public function sendDokument(
143147
$routingMyndighed = $configuration[self::ROUTING_MYNDIGHED];
144148
$routingHandlingFacet = $configuration[self::HANDLING_FACET] ?: NULL;
145149
// @todo This is probably not correct!
146-
$routingModtagerAktoer = $configuration[SettingsForm::SENDER_ID];
150+
$routingModtagerAktoer = NULL;
147151

148152
$dokument = new DistributionDokumentType(
149153
iD: $id,
@@ -294,8 +298,11 @@ private function sf2900(): SF2900 {
294298
* The combined configuration.
295299
*/
296300
public function getHandlerConfiguration(
297-
array $handlerSettings,
301+
array|WebformHandlerSF2900 $handlerSettings,
298302
): array {
303+
if ($handlerSettings instanceof WebformHandlerSF2900) {
304+
$handlerSettings = (array) $handlerSettings->getSetting(WebformHandlerSF2900::SECTION_SF2900);
305+
}
299306
$settings = $handlerSettings;
300307
$options = $this->getModuleConfig()->get('sf2900');
301308

src/Helper/WebformHelperSF2900.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\Core\Entity\EntityTypeManagerInterface;
1010
use Drupal\Core\Logger\LoggerChannelInterface;
1111
use Drupal\Core\Render\ElementInfoManagerInterface;
12+
use Drupal\Core\Utility\Token;
1213
use Drupal\os2forms_fordelingskomponent\Exception\InvalidAttachmentElementException;
1314
use Drupal\os2forms_fordelingskomponent\Exception\SubmissionNotFoundException;
1415
use Drupal\os2forms_fordelingskomponent\Form\SettingsForm;
@@ -17,6 +18,7 @@
1718
use Drupal\os2forms_fordelingskomponent\Plugin\WebformHandler\WebformHandlerSF2900;
1819
use Drupal\webform\WebformSubmissionInterface;
1920
use Drupal\webform\WebformSubmissionStorageInterface;
21+
use Drupal\webform\WebformTokenManagerInterface;
2022
use Drupal\webform_attachment\Element\WebformAttachmentBase;
2123
use Psr\Log\LoggerInterface;
2224
use Psr\Log\LoggerTrait;
@@ -48,8 +50,10 @@ final class WebformHelperSF2900 implements LoggerInterface {
4850
public function __construct(
4951
EntityTypeManagerInterface $entityTypeManager,
5052
#[Autowire(service: 'plugin.manager.element_info')]
51-
readonly protected ElementInfoManagerInterface $elementInfoManager,
53+
private readonly ElementInfoManagerInterface $elementInfoManager,
5254
private readonly FordelingskomponentHelper $helper,
55+
#[Autowire(service: 'webform.token_manager')]
56+
private readonly WebformTokenManagerInterface $webformTokenManager,
5357
#[Autowire(service: 'logger.channel.os2forms_fordelingskomponent')]
5458
private readonly LoggerChannelInterface $logger,
5559
#[Autowire(service: 'logger.channel.os2forms_fordelingskomponent_submission')]
@@ -80,9 +84,9 @@ public function afsend(WebformSubmissionInterface $submission, array $handlerSet
8084
$configuration = $this->helper->getHandlerConfiguration($handlerSettings);
8185
$attachment = $this->getAttachment($submission, $handlerSettings);
8286

83-
$titel = __METHOD__;
84-
$beskrivelse = __FILE__;
85-
$brugervendtNoegle = __METHOD__;
87+
$titel = $this->replaceTokens($configuration[FordelingskomponentHelper::TITEL] ?? '', $submission);
88+
$beskrivelse = $this->replaceTokens($configuration[FordelingskomponentHelper::BESKRIVELSE] ?? '', $submission);
89+
$brugervendtNoegle = $this->replaceTokens($configuration[FordelingskomponentHelper::BRUGERVENDT_NOEGLE] ?? '', $submission);
8690

8791
return $this->helper->sendDokument(
8892
$submission,
@@ -251,4 +255,12 @@ public function deleteMessages(array $array) {
251255
// @todo Clean up
252256
}
253257

258+
/**
259+
* Replace tokens.
260+
*/
261+
private function replaceTokens(string $text, WebformSubmissionInterface $submission): string {
262+
return $this->webformTokenManager->replace($text, $submission);
263+
}
264+
265+
254266
}

src/Plugin/WebformHandler/WebformHandlerSF2900.php

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Core\Form\FormStateInterface;
66
use Drupal\Core\Link;
7+
use Drupal\Core\Lock\NullLockBackend;
78
use Drupal\Core\StringTranslation\StringTranslationTrait;
89
use Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper;
910
use Drupal\os2forms_fordelingskomponent\Helper\WebformHelperSF2900;
@@ -29,6 +30,7 @@ final class WebformHandlerSF2900 extends WebformHandlerBase {
2930

3031
public const string ID = 'os2forms_fordelingskomponent_sf2900';
3132

33+
public const string SECTION_SF2900 = 'sf2900';
3234
public const string ATTACHMENT_ELEMENT = 'attachment_element';
3335

3436
/**
@@ -50,50 +52,81 @@ public static function create(ContainerInterface $container, array $configuratio
5052
* {@inheritdoc}
5153
*/
5254
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
53-
$form[FordelingskomponentHelper::KLE_EMNE] = [
55+
$form[static::SECTION_SF2900] = [
56+
'#type' => 'fieldset',
57+
'#title' => $this->t('Fordelingskomponent'),
58+
'#tree' => true,
59+
];
60+
61+
$configuration = $this->configuration[static::SECTION_SF2900] ?? NULL;
62+
63+
$form[static::SECTION_SF2900][FordelingskomponentHelper::KLE_EMNE] = [
5464
'#title' => $this->t('KLE-emne'),
5565
'#type' => 'textfield',
56-
'#default_value' => $this->configuration[FordelingskomponentHelper::KLE_EMNE],
66+
'#default_value' => $configuration[FordelingskomponentHelper::KLE_EMNE] ?? NULL,
5767
'#required' => TRUE,
5868
'#attributes' => [
5969
'pattern' => FordelingskomponentHelper::KLE_EMNE_PATTERN,
6070
],
6171
'#description' => $this->t('KLE-emne (format: dd.dd.dd)'),
6272
];
63-
$form[FordelingskomponentHelper::HANDLING_FACET] = [
73+
74+
$form[static::SECTION_SF2900][FordelingskomponentHelper::HANDLING_FACET] = [
6475
'#title' => $this->t('Handling-facet'),
6576
'#type' => 'textfield',
66-
'#default_value' => $this->configuration[FordelingskomponentHelper::HANDLING_FACET],
77+
'#default_value' => $configuration[FordelingskomponentHelper::HANDLING_FACET] ?? NULL,
6778
'#attributes' => [
6879
'pattern' => FordelingskomponentHelper::HANDLING_FACET_PATTERN,
6980
],
7081
];
7182

7283
$availableElements = $this->getAttachmentElements();
73-
$form[static::ATTACHMENT_ELEMENT] = [
84+
$form[static::SECTION_SF2900][static::ATTACHMENT_ELEMENT] = [
7485
'#type' => 'select',
7586
'#title' => $this->t('Element that contains the document to send'),
87+
'#default_value' => $configuration[static::ATTACHMENT_ELEMENT] ?? NULL,
7688
'#required' => TRUE,
77-
'#default_value' => $this->configuration[static::ATTACHMENT_ELEMENT] ?? NULL,
7889
'#options' => $availableElements,
7990
];
8091

81-
// @todo Change the autogenerated stub
82-
return parent::buildConfigurationForm($form, $form_state);
92+
$form[static::SECTION_SF2900][FordelingskomponentHelper::BRUGERVENDT_NOEGLE] = [
93+
'#title' => $this->t('Brugervendt nøgle'),
94+
'#type' => 'textfield',
95+
'#default_value' => $configuration[FordelingskomponentHelper::BRUGERVENDT_NOEGLE] ?? null,
96+
'#required' => true,
97+
'#description' => 'WHAT IS THIS?!',
98+
];
99+
100+
$form[static::SECTION_SF2900][FordelingskomponentHelper::TITEL] = [
101+
'#title' => $this->t('Titel'),
102+
'#type' => 'textfield',
103+
'#default_value' => $configuration[FordelingskomponentHelper::TITEL] ?? null,
104+
'#required' => true,
105+
];
106+
107+
$form[static::SECTION_SF2900][FordelingskomponentHelper::BESKRIVELSE] = [
108+
'#title' => $this->t('Beskrivelse'),
109+
'#type' => 'textarea',
110+
'#default_value' => $configuration[FordelingskomponentHelper::BESKRIVELSE] ?? NULL,
111+
'#required' => TRUE,
112+
];
113+
114+
return $this->setSettingsParents($form);
83115
}
84116

85117
/**
86118
* {@inheritdoc}
87119
*/
88120
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
89-
$kleEMne = $form_state->getValue(FordelingskomponentHelper::KLE_EMNE);
121+
$values = $form_state->getValue(static::SECTION_SF2900);
122+
$kleEMne = $values[FordelingskomponentHelper::KLE_EMNE];
90123
if (!preg_match('/' . FordelingskomponentHelper::KLE_EMNE_PATTERN . '/', (string) $kleEMne)) {
91-
$form_state->setErrorByName(FordelingskomponentHelper::KLE_EMNE, $this->t('Invalid KLE-emne: %kle_emne.', ['%kle_emne' => $kleEMne]));
124+
$form_state->setErrorByName(static::SECTION_SF2900.']['.FordelingskomponentHelper::KLE_EMNE, $this->t('Invalid KLE-emne: %kle_emne.', ['%kle_emne' => $kleEMne]));
92125
}
93126

94-
$handling_facet = $form_state->getValue(FordelingskomponentHelper::HANDLING_FACET);
127+
$handling_facet = $values[FordelingskomponentHelper::HANDLING_FACET];
95128
if (!empty($handling_facet) && !preg_match('/' . FordelingskomponentHelper::HANDLING_FACET_PATTERN . '/', (string) $handling_facet)) {
96-
$form_state->setErrorByName(FordelingskomponentHelper::HANDLING_FACET,
129+
$form_state->setErrorByName(static::SECTION_SF2900.']['.FordelingskomponentHelper::HANDLING_FACET,
97130
$this->t('Invalid Handling-facet: %handling_facet.', ['%handling_facet' => $handling_facet]));
98131
}
99132

@@ -106,10 +139,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
106139
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
107140
parent::submitConfigurationForm($form, $form_state);
108141

109-
$this->configuration[FordelingskomponentHelper::KLE_EMNE] = $form_state->getValue(FordelingskomponentHelper::KLE_EMNE);
110-
$this->configuration[FordelingskomponentHelper::HANDLING_FACET] = $form_state->getValue(FordelingskomponentHelper::HANDLING_FACET);
111-
$this->configuration[static::ATTACHMENT_ELEMENT] = $form_state->getValue(static::ATTACHMENT_ELEMENT);
112-
142+
$this->configuration[static::SECTION_SF2900] = $form_state->getValue(static::SECTION_SF2900);
113143
}
114144

115145
/**
@@ -121,7 +151,7 @@ public function postSave(WebformSubmissionInterface $webform_submission, $update
121151
return;
122152
}
123153

124-
$this->helper->createJob($webform_submission, $this->configuration);
154+
$this->helper->createJob($webform_submission, $this->configuration[static::SECTION_SF2900]);
125155
}
126156

127157
/**

0 commit comments

Comments
 (0)