66
77use Composer \Console \Input \InputOption ;
88use Drupal \Core \Entity \EntityTypeManagerInterface ;
9+ use Drupal \Core \Url ;
910use Drupal \os2forms_fordelingskomponent \Helper \FordelingskomponentHelper ;
1011use Drupal \os2forms_fordelingskomponent \Helper \WebformHelperSF2900 ;
1112use 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 ;
0 commit comments