From 3b63b64c3889edc7736a98ea2235471c96c44036 Mon Sep 17 00:00:00 2001 From: Patryk Kula Date: Fri, 9 Feb 2024 15:18:02 +0100 Subject: [PATCH] Fix: Migration to ensure compatibility with Symfony 5 for nested fields (#433) --- UPGRADE.md | 3 +++ .../Migrations/Version20211011171530.php | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 381c0cd6..451ef57e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,8 @@ # Upgrade Notes +## 4.5.2 +- **[BUGFIX]**: Fix element type check in api channel [@patkul0](https://github.com/dachcom-digital/pimcore-formbuilder/pull/433) + ## 4.5.1 - **[BUGFIX]**: Fix element type check in api channel [#423](https://github.com/dachcom-digital/pimcore-formbuilder/issues/423) diff --git a/src/FormBuilderBundle/Migrations/Version20211011171530.php b/src/FormBuilderBundle/Migrations/Version20211011171530.php index 14828a08..0e315da6 100644 --- a/src/FormBuilderBundle/Migrations/Version20211011171530.php +++ b/src/FormBuilderBundle/Migrations/Version20211011171530.php @@ -55,13 +55,13 @@ public function up(Schema $schema): void $configuration = $data['config'] ?? []; $conditionalLogic = $data['conditional_logic'] ?? []; - $fields = $data['fields'] ?? []; - $fixedFields = $this->ensureSymfony5Compatibility($fields); + $fields = $data['fields'] ?? []; + $this->ensureSymfony5Compatibility($fields); $this->addSql(sprintf('UPDATE formbuilder_forms SET `configuration` = "%s" WHERE `id` = %d', addslashes(serialize($configuration)), $formDefinitionId)); $this->addSql(sprintf('UPDATE formbuilder_forms SET `conditionalLogic` = "%s" WHERE `id` = %d', addslashes(serialize($conditionalLogic)), $formDefinitionId)); - $this->addSql(sprintf('UPDATE formbuilder_forms SET `fields` = "%s" WHERE `id` = %d', addslashes(serialize($fixedFields)), $formDefinitionId)); + $this->addSql(sprintf('UPDATE formbuilder_forms SET `fields` = "%s" WHERE `id` = %d', addslashes(serialize($fields)), $formDefinitionId)); } } @@ -70,10 +70,9 @@ public function down(Schema $schema): void // disabled } - private function ensureSymfony5Compatibility(array $fields): array + private function ensureSymfony5Compatibility(array &$fields): void { - $fixedFields = []; - foreach ($fields as $field) { + foreach ($fields as &$field) { if ($field['type'] === 'choice') { $this->fixChoiceField($field); } @@ -82,10 +81,10 @@ private function ensureSymfony5Compatibility(array $fields): array $this->fixConstraints($field); } - $fixedFields[] = $field; + if (isset($field['fields']) && is_array($field['fields'])) { + $this->ensureSymfony5Compatibility($field['fields']); + } } - - return $fixedFields; } private function fixChoiceField(array &$field): void