Fixed initial Flex Object state when creating a new objects in a form

This commit is contained in:
Matias Griese
2019-09-19 21:58:28 +03:00
parent 1ad2a3f212
commit 7b2313ef0b
3 changed files with 7 additions and 3 deletions

View File

@@ -18,6 +18,7 @@
* Fixed 404 error when you click to non-routable menu item with children: redirect to the first child instead
* Fixed wrong `Pages::dispatch()` calls (with redirect) when we really meant to call `Pages::find()`
* Fixed avatars not being displayed with flex users [#2431](https://github.com/getgrav/grav/issues/2431)
* Fixed initial Flex Object state when creating a new objects in a form
# v1.7.0-beta.7
## 08/30/2019

View File

@@ -132,6 +132,7 @@ class FlexForm implements FlexFormInterface
$data = $flash->getData();
$includeOriginal = (bool)($this->getBlueprint()->form()['images']['original'] ?? null);
$this->object = $flash->getObject();
$this->data = $data ? new Data($data, $this->getBlueprint()) : null;
$this->files = $flash->getFilesByFields($includeOriginal);
}

View File

@@ -38,9 +38,9 @@ class FlexFormFlash extends FormFlash
$serialized['object'] = [
'type' => $object->getFlexType(),
'key' => $object->getKey() ?: null,
'storage_key' => $object->exists() ? $object->getStorageKey() : null,
'storage_key' => $object->getStorageKey(),
'timestamp' => $object->getTimestamp(),
'serialized' => $object->jsonSerialize()
'serialized' => $object->prepareStorage()
];
}
@@ -51,9 +51,11 @@ class FlexFormFlash extends FormFlash
{
parent::init($data, $config);
/** @var FlexObjectInterface $object */
$object = $config['object'];
if (isset($data['object']['serialized']) && !$object->exists()) {
$object->update($data['object']['serialized']);
// TODO: update instead of create new.
$object = $object->getFlexDirectory()->createObject($data['object']['serialized'], $data['object']['key']);
}
$this->setObject($object);