Skip to content

Commit 3c137df

Browse files
committed
Added preview URLs and stuff to validate XML command output
1 parent 8584f65 commit 3c137df

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/Drush/Commands/ValidateXmlCommand.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Composer\Console\Input\InputOption;
88
use Drupal\Core\Entity\EntityTypeManagerInterface;
9+
use Drupal\Core\Url;
910
use Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper;
1011
use Drupal\os2forms_fordelingskomponent\Helper\WebformHelperSF2900;
1112
use Drupal\os2forms_fordelingskomponent\Plugin\WebformHandler\WebformHandlerSF2900;
@@ -58,6 +59,7 @@ protected function configure(): void {
5859
->addArgument('webform-id', InputArgument::REQUIRED, 'Webform ID')
5960
->addArgument('handler-id', InputArgument::REQUIRED, 'Handler ID')
6061
->addOption('show-xml', NULL, InputOption::VALUE_NONE, 'Show XML')
62+
->addOption('show-render-context', NULL, InputOption::VALUE_NONE, 'Show render context')
6163
->addOption('break-on-error', NULL, InputOption::VALUE_OPTIONAL, 'Break on error. If set, terminate after first error.', FALSE);
6264
}
6365

@@ -70,6 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7072
$webformId = $input->getArgument('webform-id');
7173
$handlerId = $input->getArgument('handler-id');
7274
$showXml = (bool) $input->getOption('show-xml');
75+
$showRenderContext = (bool) $input->getOption('show-render-context');
7376
$breakOnError = filter_var($input->getOption('break-on-error') ?? TRUE, FILTER_VALIDATE_BOOLEAN);
7477

7578
$io = new SymfonyStyle($input, $output);
@@ -84,14 +87,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8487
else {
8588
foreach ($submissions as $submission) {
8689
$preview = $this->webformHelper->renderPreview($handler, $submission);
90+
$previewUrl = Url::fromRoute('os2forms_fordelingskomponent.fordelingskomponent_distribution_object.preview', [
91+
'webform' => $webform->id(),
92+
'webform_handler' => $handler->getHandlerId(),
93+
'webform_submission' => $submission->id(),
94+
])
95+
->setAbsolute()
96+
->toString(TRUE)->getGeneratedUrl();
8797
$hasErrors = count($preview['exceptions']) > 0;
8898
if ($hasErrors) {
89-
foreach ($preview['exceptions'] as $exception) {
90-
$io->error([$submission->label(), $exception->getMessage()]);
91-
}
99+
$io->error([
100+
$submission->label(),
101+
$previewUrl,
102+
...array_map(static fn (\Exception $exception) => $exception->getMessage(), $preview['exceptions']),
103+
]);
92104
}
93105
else {
94-
$io->success($submission->label());
106+
$io->success([
107+
$submission->label(),
108+
$previewUrl,
109+
]);
95110
}
96111

97112
if ($showXml) {
@@ -103,6 +118,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103118
}
104119
}
105120

121+
if ($showRenderContext) {
122+
$io->writeln(json_encode($preview['xml']->context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
123+
}
124+
106125
if ($hasErrors) {
107126
if ($breakOnError) {
108127
return self::FAILURE;

src/Model/XmlRenderResult.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
*/
1515
public function __construct(
1616
public string $template,
17+
/**
18+
* The context.
19+
*
20+
* @var array{
21+
* submission: array,
22+
* files: array,
23+
* handler: array,
24+
* }
25+
*/
1726
public array $context,
1827
public ?string $rendered,
1928
public ?\Exception $exception,

0 commit comments

Comments
 (0)