diff --git a/CHANGELOG.md b/CHANGELOG.md index 63f298f..0f5280e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.3.0] + +- Handled webform categories now being an array. +- Rendered wizard pages as 'details' elements in previews. + ### Updated ## [1.2.1] @@ -50,7 +55,8 @@ Versioning](https://semver.org/spec/v2.0.0.html). - Added OS2Forms sync module -[Unreleased]: https://github.com/itk-dev/os2forms_sync/compare/1.2.1...HEAD +[Unreleased]: https://github.com/itk-dev/os2forms_sync/compare/1.3.0...HEAD +[1.3.0]: https://github.com/itk-dev/os2forms_sync/compare/1.2.1...1.3.0 [1.2.1]: https://github.com/itk-dev/os2forms_sync/compare/1.2.0...1.2.1 [1.2.0]: https://github.com/itk-dev/os2forms_sync/compare/1.1.3...1.2.0 [1.1.3]: https://github.com/itk-dev/os2forms_sync/compare/1.1.2...1.1.3 diff --git a/src/Controller/WebformController.php b/src/Controller/WebformController.php index c4e3233..42b5d03 100644 --- a/src/Controller/WebformController.php +++ b/src/Controller/WebformController.php @@ -184,7 +184,7 @@ public function index(): array { '#type' => 'container', '#attributes' => [ 'class' => ['category'], - 'data-indexed' => strip_tags($attributes['category']), + 'data-indexed' => implode(', ', json_decode($attributes['categories'])), ], 'label' => [ @@ -199,7 +199,7 @@ public function index(): array { '#attributes' => [ 'class' => ['value'], ], - '#value' => $attributes['category'], + '#value' => implode(', ', json_decode($attributes['categories'])), ], ], diff --git a/src/Helper/JsonAPISerializer.php b/src/Helper/JsonAPISerializer.php index 13b6c97..b10e154 100644 --- a/src/Helper/JsonAPISerializer.php +++ b/src/Helper/JsonAPISerializer.php @@ -80,13 +80,15 @@ static function ($key) { return in_array($key, [ 'title', 'description', - 'category', + 'categories', 'elements', ]); }, ARRAY_FILTER_USE_KEY ); + $attributes['categories'] = json_encode($attributes['categories']); + $attributes = array_map('html_entity_decode', $attributes); if (isset($attributes['elements'])) { diff --git a/src/Helper/WebformHelper.php b/src/Helper/WebformHelper.php index 520892e..1ec4f48 100644 --- a/src/Helper/WebformHelper.php +++ b/src/Helper/WebformHelper.php @@ -175,6 +175,26 @@ public function theme(array $existing, string $type, string $theme, string $path * @phpstan-return array */ public function getSubmissionForm(array $elements): array { + + // Webforms that are rendered here are not a part of the database yet. + // As a consequence, any element that attempts to load the webform will be + // unable to do so. + // Wizard pages attempt to do so in WebformWizardPage::showPage, so we + // display these as 'details' instead and indicate that they originally + // are pages in their titles. + $isFirst = TRUE; + foreach ($elements as &$element) { + if (($element['#type'] ?? NULL) === 'webform_wizard_page') { + if ($isFirst) { + $element['#open'] = TRUE; + $isFirst = FALSE; + } + + $element['#type'] = 'details'; + $element['#title'] = (string) $this->t('%title% (wizard page)', ['%title%' => $element['#title']]); + } + } + $webform = Webform::create([ 'id' => (new Random())->name(32), 'elements' => Yaml::encode($elements),