Skip to content

Commit 65c174e

Browse files
committed
Cleaned up preview
1 parent 22b0480 commit 65c174e

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/Controller/Os2formsFordelingskomponentDistributionObjectPreviewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function renderPreview(WebformHandlerSF2900 $handler, HandlerSettings $ha
9595
'exceptions' => $exceptions,
9696
'warnings' => $warnings,
9797
'distribution_object' => $distributionObject,
98-
'xml' => $xml,
98+
'xml' => $xml->withContextAsArray(),
9999
];
100100
}
101101

src/Helper/XmlHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ public function render(string $template, array $context, bool $validateXml = TRU
7070
*/
7171
public function getRenderContext(HandlerSettings $handlerSettings, WebformSubmissionInterface $submission, array $files) {
7272
return [
73-
'handler' => ['settings' => $handlerSettings],
7473
'submission' => $submission,
75-
'webform_submission' => $submission,
7674
'files' => $files,
75+
'handler' => ['settings' => $handlerSettings],
7776
];
7877
}
7978

src/Model/XmlRenderResult.php

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

33
namespace Drupal\os2forms_fordelingskomponent\Model;
44

5+
use Drupal\webform\WebformSubmissionInterface;
6+
57
/**
68
* The Document class.
79
*/
@@ -11,10 +13,29 @@
1113
* Constructor.
1214
*/
1315
public function __construct(
14-
public string $rendered,
1516
public string $template,
1617
public array $context,
18+
public ?string $rendered,
19+
public ?\Exception $exception,
1720
) {
1821
}
1922

23+
/**
24+
* Convert objects in context to arrays.
25+
*/
26+
public function withContextAsArray(): self {
27+
$context = $this->context;
28+
if (($context['submission'] ?? NULL) instanceof WebformSubmissionInterface) {
29+
$context['submission'] = $context['submission']->toArray(TRUE, TRUE);
30+
}
31+
// @todo Convert 'handler' and 'files'
32+
return new self(
33+
$this->template,
34+
$context,
35+
$this->rendered,
36+
$this->exception,
37+
);
38+
39+
}
40+
2041
}

templates/base.html.twig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@
8383
<fieldset>
8484
<legend>{{ label }}</legend>
8585

86+
{#
8687
{% set data_url = 'data:application/json,' ~ (value|json_encode|url_encode) %}
8788
<iframe src="{{ data_url }}"></iframe>
8889
<a target="_blank" href="{{ data_url }}">{{ 'Open data in new tab'|trans }}</a>
90+
#}
8991

9092
<pre><code>{{ value|json_encode(constant('JSON_PRETTY_PRINT') b-or constant('JSON_UNESCAPED_UNICODE')) }}</code></pre>
9193
</fieldset>
@@ -95,13 +97,12 @@
9597
<fieldset>
9698
<legend>{{ label }}</legend>
9799

100+
{#
98101
{% set data_url = 'data:text/xml,' ~ (value|url_encode) %}
99102
<iframe src="{{ data_url }}"></iframe>
100103
<a target="_blank" href="{{ data_url }}">{{ 'Open data in new tab'|trans }}</a>
104+
#}
101105

102-
<details>
103-
<summary>{{ 'Raw content'|trans }}</summary>
104-
<pre><code>{{ value }}</code></pre>
105-
</details>
106+
<pre><code>{{ value }}</code></pre>
106107
</fieldset>
107108
{% endmacro %}

0 commit comments

Comments
 (0)