Skip to content

Commit d7aef81

Browse files
committed
Cleaned up
1 parent 818b66b commit d7aef81

9 files changed

Lines changed: 75 additions & 105 deletions

src/Controller/Os2formsFordelingskomponentDistributionObjectPreviewRenderController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Drupal\Core\Controller\ControllerBase;
88
use Drupal\Core\Render\RendererInterface;
99
use Drupal\os2forms_fordelingskomponent\Helper\WebformHelperSF2900;
10-
use Drupal\os2forms_fordelingskomponent\Helper\XmlHelper;
1110
use Drupal\os2forms_fordelingskomponent\Hook\ThemeHooks;
11+
use Drupal\os2forms_fordelingskomponent\Model\Attachment;
1212
use Drupal\os2forms_fordelingskomponent\Plugin\WebformHandler\WebformHandlerSF2900;
1313
use Drupal\os2forms_fordelingskomponent\Settings;
1414
use Drupal\webform\WebformInterface;
@@ -25,7 +25,6 @@ public function __construct(
2525
private readonly Settings $settings,
2626
private readonly WebformHelperSF2900 $helper,
2727
private readonly RendererInterface $renderer,
28-
private readonly XmlHelper $xmlHelper,
2928
) {
3029
}
3130

@@ -52,7 +51,8 @@ public function __invoke(WebformInterface $webform, string $webform_handler, Web
5251
$distributionObject = NULL;
5352
$xml = [];
5453
try {
55-
$distributionObject = $this->helper->buildDistributionObject($handlerSettings, $submission);
54+
$attachment = new Attachment('preview', Attachment::MIME_TYPE_PDF, 'preview.pdf');
55+
$distributionObject = $this->helper->buildDistributionObject($handlerSettings, $submission, $attachment);
5656
}
5757
catch (\Exception $exception) {
5858
$exceptions[] = $exception;

src/Helper/FordelingskomponentHelper.php

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
use Psr\Log\LoggerTrait;
5252
use Symfony\Component\DependencyInjection\Attribute\Autowire;
5353
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
54-
use WsdlToPhp\PackageBase\AbstractStructBase;
5554

5655
/**
5756
* Fordelingskomponent helper.
@@ -61,16 +60,6 @@
6160
final class FordelingskomponentHelper implements LoggerInterface {
6261
use LoggerTrait;
6362

64-
public const string ROUTING_MYNDIGHED = 'routing_myndighed';
65-
66-
public const string KLE_EMNE = 'kle_emne';
67-
68-
public const string HANDLING_FACET = 'handling_facet';
69-
public const string TITEL = 'titel';
70-
public const string BESKRIVELSE = 'beskrivelse';
71-
72-
public const string ATTACHMENT_ELEMENT = 'attachment_element';
73-
7463
/**
7564
* Constructor.
7665
*/
@@ -133,11 +122,9 @@ public function buildDistributionObject(
133122
),
134123
DistributionObjectSettings::DISTRIBUTION_TYPE_FORMULAR => $this->buildDistributionFormularType(
135124
id: $id,
136-
fraTidsPunkt: $fraTidsPunkt,
137-
brevDato: $brevDato,
138-
submission: $submission,
139-
handlerSettings: $handlerSettings,
140-
attachment: $attachment,
125+
submission: $submission,
126+
handlerSettings: $handlerSettings,
127+
attachment: $attachment,
141128
),
142129
default => throw new Exception(sprintf('Invalid distribution type: %s', $type)),
143130
};
@@ -194,57 +181,57 @@ private function buildDistributionDokumentType(
194181
): DistributionDokumentType {
195182
return new DistributionDokumentType(
196183
iD: $id,
197-
kLEEmneForslag: $handlerSettings->distributionContext->kleEmne,
198-
handlingFacetForslag: $handlerSettings->distributionContext->handlingFacet,
199-
registrering: new DokumentRegistreringType(
200-
fraTidsPunkt: SF2900::formatDateTime($fraTidsPunkt),
201-
livscyklusKode: LivscyklusKodeType::VALUE_OPRETTET,
202-
registreringItSystem: new UUID_URN($handlerSettings->sender->registreringItSystem),
203-
relationListe: new RelationsListe(
204-
variantListe: new VariantListeType([
205-
new VariantType(
206-
// If we don't clone the “virking", the XML serializer adds an
207-
// ID and references which SF2900 does not handle.
208-
virkning: $this->clone($virkning),
209-
rolle: VariantRolleType::VALUE_VARIANT,
210-
indeks: '1',
211-
variantAttributter: new VariantAttributterType(
184+
kLEEmneForslag: $handlerSettings->distributionContext->kleEmne,
185+
registrering: new DokumentRegistreringType(
186+
fraTidsPunkt: SF2900::formatDateTime($fraTidsPunkt),
187+
livscyklusKode: LivscyklusKodeType::VALUE_OPRETTET,
188+
registreringItSystem: new UUID_URN($handlerSettings->sender->registreringItSystem),
189+
relationListe: new RelationsListe(
190+
variantListe: new VariantListeType([
191+
new VariantType(
192+
// If we don't clone the “virking", the XML serializer adds an
193+
// ID and references which SF2900 does not handle.
194+
virkning: $this->cloneVirkning($virkning),
195+
rolle: VariantRolleType::VALUE_VARIANT,
196+
indeks: '1',
197+
variantAttributter: new VariantAttributterType(
198+
// @todo What to use here?
199+
variantType: Attachment::FORMAT_NAME_PDF,
200+
),
201+
delAttributter: new DelAttributterType(
212202
// @todo What to use here?
213-
variantType: Attachment::FORMAT_NAME_PDF,
203+
delTekst: 'Hele dokumentet',
204+
),
214205
),
215-
delAttributter: new DelAttributterType(
206+
]),
207+
),
208+
tilstandsListe: [
209+
new TilstandListeType(
210+
tilstand: [
211+
new TilstandType(
212+
// @todo Hvad er fremdrift?
213+
fremdrift: FremdriftType::VALUE_ENDELIGT,
214+
virkning: $this->cloneVirkning($virkning),
215+
),
216+
]
217+
),
218+
],
219+
attributListe: new AttributterListeType([
220+
new AttributterType(
221+
brugervendtNoegleTekst: $handlerSettings->distributionContext->brugervendtNoegle,
222+
titelTekst: $handlerSettings->distributionContext->titel,
223+
beskrivelseTekst: $handlerSettings->distributionContext->beskrivelse,
216224
// @todo What to use here?
217-
delTekst: 'Hele dokumentet',
218-
),
225+
dokumenttype: DokumenttypeType::VALUE_ANDEN,
226+
retning: RetningType::VALUE_UDGAAENDE,
227+
brevdato: SF2900::formatDate($brevDato),
228+
virkning: $this->cloneVirkning($virkning),
219229
),
220230
]),
231+
// importTidspunkt: null,
232+
// brugerRef: null,.
221233
),
222-
tilstandsListe: [
223-
new TilstandListeType(
224-
tilstand: [
225-
new TilstandType(
226-
// @todo Hvad er fremdrift?
227-
fremdrift: FremdriftType::VALUE_ENDELIGT,
228-
virkning: $this->clone($virkning),
229-
),
230-
]
231-
),
232-
],
233-
attributListe: new AttributterListeType([
234-
new AttributterType(
235-
brugervendtNoegleTekst: $handlerSettings->distributionContext->brugervendtNoegle,
236-
titelTekst: $handlerSettings->distributionContext->titel,
237-
beskrivelseTekst: $handlerSettings->distributionContext->beskrivelse,
238-
// @todo What to use here?
239-
dokumenttype: DokumenttypeType::VALUE_ANDEN,
240-
retning: RetningType::VALUE_UDGAAENDE,
241-
brevdato: SF2900::formatDate($brevDato),
242-
virkning: $this->clone($virkning),
243-
),
244-
]),
245-
// importTidspunkt: null,
246-
// brugerRef: null,.
247-
)
234+
handlingFacetForslag: $handlerSettings->distributionContext->handlingFacet
248235
);
249236
}
250237

@@ -253,8 +240,6 @@ private function buildDistributionDokumentType(
253240
*/
254241
private function buildDistributionFormularType(
255242
string $id,
256-
\DateTimeInterface $fraTidsPunkt,
257-
\DateTimeInterface $brevDato,
258243
WebformSubmissionInterface $submission,
259244
HandlerSettings $handlerSettings,
260245
Attachment $attachment,
@@ -272,13 +257,20 @@ private function buildDistributionFormularType(
272257
$formatNavn = pathinfo($attachment->filename, PATHINFO_EXTENSION);
273258
$formularIndhold = base64_encode($attachment->contents);
274259

260+
// The XML will be embedded in an SOAP:Envelope element, so we have to
261+
// make sure that the XML declaration is not included when embedding.
262+
// Passing a DOMDocument to FormularXMLType takes care of this.
263+
$dom = new \DOMDocument();
264+
$dom->loadXML($xml);
265+
$formularXML = new FormularXMLType($dom);
266+
275267
$meddelelse = new MeddelelseType(
276268
formularType: $handlerSettings->distributionObject->formularType,
277269
formular: new FormularType(
278270
titelTekst: $titelTekst,
279271
formatNavn: $formatNavn,
280272
formularIndhold: $formularIndhold,
281-
formularXML: new FormularXMLType($xml),
273+
formularXML: $formularXML,
282274
),
283275
);
284276

@@ -439,16 +431,16 @@ private function buildVirkning(HandlerSettings $handlerSettings): VirkningType {
439431
}
440432

441433
/**
442-
* Deep clone an object.
434+
* Deep clone a virking.
443435
*
444-
* @param \WsdlToPhp\PackageBase\AbstractStructBase<T> $object
436+
* @param \ItkDev\Serviceplatformen\SF2900\StructType\VirkningType $virkning
445437
* The object to clone.
446438
*
447-
* @return \WsdlToPhp\PackageBase\AbstractStructBase<T>
439+
* @return \ItkDev\Serviceplatformen\SF2900\StructType\VirkningType
448440
* The cloned object.
449441
*/
450-
private function clone(AbstractStructBase $object): AbstractStructBase {
451-
return unserialize(serialize($object));
442+
private function cloneVirkning(VirkningType $virkning): VirkningType {
443+
return unserialize(serialize($virkning));
452444
}
453445

454446
}

src/Helper/WebformHelperSF2900.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Drupal\Core\Entity\EntityStorageInterface;
99
use Drupal\Core\Entity\EntityTypeManagerInterface;
1010
use Drupal\Core\Logger\LoggerChannelInterface;
11-
use Drupal\Core\Render\ElementInfoManagerInterface;
11+
use Drupal\Core\Render\ElementInfoManager;
1212
use Drupal\os2forms_fordelingskomponent\Exception\InvalidAttachmentElementException;
1313
use Drupal\os2forms_fordelingskomponent\Exception\SubmissionNotFoundException;
1414
use Drupal\os2forms_fordelingskomponent\Model\Attachment;
@@ -56,7 +56,7 @@ public function __construct(
5656
EntityTypeManagerInterface $entityTypeManager,
5757
private readonly Settings $settings,
5858
#[Autowire(service: 'plugin.manager.element_info')]
59-
private readonly ElementInfoManagerInterface $elementInfoManager,
59+
private readonly ElementInfoManager $elementInfoManager,
6060
private readonly FordelingskomponentHelper $helper,
6161
#[Autowire(service: 'webform.token_manager')]
6262
private readonly WebformTokenManagerInterface $webformTokenManager,
@@ -92,16 +92,8 @@ public function renderXml(HandlerSettings $handlerSettings, WebformSubmissionInt
9292
/**
9393
* Afsend med Fordelingskomponenten.
9494
*
95-
* @param \Drupal\webform\WebformSubmissionInterface $submission
96-
* The submission.
97-
* @param array $handlerSettings
98-
* The Handler settings.
99-
*
10095
* @return array
10196
* [The response, The kombi post message].
102-
*
103-
* @phpstan-param array<string, mixed> $handlerSettings
104-
* @phpstan-param array<string, mixed> $submissionData
10597
*/
10698
public function afsend(WebformSubmissionInterface $submission, HandlerSettings $handlerSettings): array {
10799
$attachment = $this->getAttachment($submission, $handlerSettings);
@@ -119,8 +111,6 @@ public function afsend(WebformSubmissionInterface $submission, HandlerSettings $
119111
* Get main document.
120112
*
121113
* @see WebformAttachmentController::download()
122-
*
123-
* @phpstan-param array<string, mixed> $handlerSettings
124114
*/
125115
protected function getAttachment(WebformSubmissionInterface $submission, HandlerSettings $handlerSettings): ?Attachment {
126116
if (!in_array($handlerSettings->distributionObject->distributionType, [
@@ -197,8 +187,6 @@ public function log($level, $message, array $context = []): void {
197187
* Create a job.
198188
*
199189
* @see self::processJob()
200-
*
201-
* @phpstan-param array<string, mixed> $handlerConfiguration
202190
*/
203191
public function createJob(WebformSubmissionInterface $webformSubmission, WebformHandlerSF2900 $handler): ?Job {
204192
$context = [

src/Helper/XmlHelper.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Drupal\os2forms_fordelingskomponent\Helper;
44

5-
use Drupal\Core\Config\ImmutableConfig;
6-
use Drupal\Core\Config\ConfigFactoryInterface;
75
use Drupal\os2forms_fordelingskomponent\Exception\InvalidXmlTemplateException;
86
use Drupal\os2forms_fordelingskomponent\Settings\HandlerSettings;
97
use Drupal\webform\WebformSubmissionInterface;
@@ -15,20 +13,14 @@
1513
* XML helper.
1614
*/
1715
class XmlHelper {
18-
/**
19-
* The module config.
20-
*/
21-
private ImmutableConfig $moduleSettings;
2216

2317
/**
2418
* Constructor.
2519
*/
2620
public function __construct(
2721
#[Autowire(service: 'twig')]
2822
private readonly Environment $twig,
29-
ConfigFactoryInterface $configFactory,
3023
) {
31-
$this->moduleSettings = $configFactory->get('os2forms_fordelingskomponent.settings');
3224
}
3325

3426
/**

src/Plugin/WebformHandler/WebformHandlerSF2900.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ final class WebformHandlerSF2900 extends WebformHandlerBase {
3939
/**
4040
* The settings.
4141
*/
42-
private readonly Settings $settingsService;
42+
private Settings $settingsService;
4343

4444
/**
4545
* The webform helper.
4646
*/
47-
private readonly WebformHelperSF2900 $helper;
47+
private WebformHelperSF2900 $helper;
4848

4949
/**
5050
* The XML helper.
5151
*/
52-
private readonly XmlHelper $xmlHelper;
52+
private XmlHelper $xmlHelper;
5353

5454
/**
5555
* {@inheritdoc}
@@ -256,7 +256,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
256256

257257
$type = $form_state->getValue(DistributionObjectSettings::NAME)[DistributionObjectSettings::DISTRIBUTION_TYPE] ?? '';
258258
if (DistributionObjectSettings::DISTRIBUTION_TYPE_FORMULAR === $type) {
259-
$template = (string) $form_state->getValue(DistributionObjectSettings::NAME)[DistributionObjectSettings::XML_TEMPLATE] ?? '';
259+
$template = (string) ($form_state->getValue(DistributionObjectSettings::NAME)[DistributionObjectSettings::XML_TEMPLATE] ?? NULL);
260260
try {
261261
$this->xmlHelper->validateXml($template);
262262
$this->xmlHelper->validateTemplate($template);
@@ -266,7 +266,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
266266
$this->t('Invalid XML template: %message.', ['%message' => $e->getMessage()]));
267267
}
268268

269-
$url = (string) $form_state->getValue(DistributionObjectSettings::NAME)[DistributionObjectSettings::XSD_URL] ?? '';
269+
$url = (string) ($form_state->getValue(DistributionObjectSettings::NAME)[DistributionObjectSettings::XSD_URL] ?? NULL);
270270
if ($url) {
271271
$contents = @file_get_contents($url);
272272
if (FALSE === $contents) {

src/Settings/DistributionObjectSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use ItkDev\Serviceplatformen\SF2900\EnumType\ObjektTypeType;
66

77
/**
8-
* General DistributionContext settings, i.e. the ones that do not depend o a specific distribution object.
8+
* Distribution object settings.
99
*
1010
* @see https://rimi-itk.github.io/digitaliseringskataloget.dk/digitaliseringskataloget.dk/sf2900/2.4/SF2900%20-%20Fordelingskomponent%20V2.4.pdf#page=34
1111
*/

src/Settings/SenderSettings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Drupal\os2forms_fordelingskomponent\Settings\SenderSettings\SftpSettings;
66

77
/**
8+
* Sender settings.
9+
*
810
* @see https://rimi-itk.github.io/digitaliseringskataloget.dk/digitaliseringskataloget.dk/sf2900/2.4/SF2900%20-%20Fordelingskomponent%20V2.4.pdf
911
*/
1012
final class SenderSettings extends AbstractSettings {

templates/os2forms-fordelingskomponent-distribution-object-preview.html.twig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
#}
2020
{% block content %}
21-
22-
{{ dump() }}
23-
2421
<details>
2522
<summary>{{ 'XML Template'|t }}</summary>
2623
<pre><code>{{ handler_settings.distributionObject.xmlTemplate }}</code></pre>

templates/os2forms-fordelingskomponent-routing-info.html.twig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@
1414
*/
1515
#}
1616
{% block content %}
17-
{{ _self.render_json(info) }}
18-
17+
{{ _self.render_json(info) }}
1918
{% endblock %}

0 commit comments

Comments
 (0)