Skip to content

Commit af518d8

Browse files
committed
Handled rendering of wizard pages in previews
1 parent 8670239 commit af518d8

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/Helper/WebformHelper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ public function theme(array $existing, string $type, string $theme, string $path
175175
* @phpstan-return array<string, mixed>
176176
*/
177177
public function getSubmissionForm(array $elements): array {
178+
179+
// Webforms that are rendered here are not a part of the database yet.
180+
// As a consequence, any element that attempts to load the webform will be
181+
// unable to do so.
182+
// Wizard pages attempt to do so in WebformWizardPage::showPage, so we
183+
// display these as 'details' instead and indicate that they originally
184+
// are pages in their titles.
185+
$isFirst = TRUE;
186+
foreach ($elements as &$element) {
187+
if (($element['#type'] ?? NULL) === 'webform_wizard_page') {
188+
if ($isFirst) {
189+
$element['#open'] = TRUE;
190+
$isFirst = FALSE;
191+
}
192+
193+
$element['#type'] = 'details';
194+
$element['#title'] = (string) $this->t('%title% (wizard page)', ['%title%' => $element['#title']]);
195+
}
196+
}
197+
178198
$webform = Webform::create([
179199
'id' => (new Random())->name(32),
180200
'elements' => Yaml::encode($elements),

0 commit comments

Comments
 (0)