From c9159695aa0390bcc8d4970bdfde29337e98aec7 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 29 Jul 2021 19:59:42 +0300 Subject: [PATCH] Fixed `FlexForm` serialization --- CHANGELOG.md | 1 + system/src/Grav/Framework/Flex/FlexForm.php | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31f12f0af..f30e33f5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fixed broken `environment://` stream when it doesn't have configuration * Fixed `Flex Object` missing key field value when using `FolderStorage` * Fixed broken Twig try tag when catch has not been defined or is empty + * Fixed `FlexForm` serialization # v1.7.18 ## 07/19/2021 diff --git a/system/src/Grav/Framework/Flex/FlexForm.php b/system/src/Grav/Framework/Flex/FlexForm.php index 192f38fec..3625189b2 100644 --- a/system/src/Grav/Framework/Flex/FlexForm.php +++ b/system/src/Grav/Framework/Flex/FlexForm.php @@ -103,7 +103,14 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable { $this->name = $name; $this->setObject($object); - $this->setName($object->getFlexType(), $name); + + if (isset($options['form']['name'])) { + // Use custom form name. + $this->flexName = $options['form']['name']; + } else { + // Use standard form name. + $this->setName($object->getFlexType(), $name); + } $this->setId($this->getName()); $uniqueId = $options['unique_id'] ?? null; @@ -536,7 +543,11 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable protected function doSerialize(): array { return $this->doTraitSerialize() + [ + 'items' => $this->items, + 'form' => $this->form, 'object' => $this->object, + 'flexName' => $this->flexName, + 'submitMethod' => $this->submitMethod, ]; } @@ -548,7 +559,11 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable { $this->doTraitUnserialize($data); - $this->object = $data['object']; + $this->items = $data['items'] ?? null; + $this->form = $data['form'] ?? null; + $this->object = $data['object'] ?? null; + $this->flexName = $data['flexName'] ?? null; + $this->submitMethod = $data['submitMethod'] ?? null; } /**