diff --git a/application/src/Api/Adapter/SitePageAdapter.php b/application/src/Api/Adapter/SitePageAdapter.php index 5a4fb6c83..dd1a042a1 100644 --- a/application/src/Api/Adapter/SitePageAdapter.php +++ b/application/src/Api/Adapter/SitePageAdapter.php @@ -228,8 +228,16 @@ private function hydrateBlocks(array $blockData, SitePage $page, ErrorStore $err return; } if (!is_array($inputBlock['o:data'])) { - $errorStore->addError('o:block', 'Block data must not be a scalar value.'); // @translate - return; + // Attempt to convert the data to an array before returning with + // an error. This is needed in part so fallback blocks don't + // lose their data onced saved. + $blockData = json_decode($inputBlock['o:data'], true); + if (is_array($blockData)) { + $inputBlock['o:data'] = $blockData; + } else { + $errorStore->addError('o:block', 'Block data must not be a scalar value.'); // @translate + return; + } } $block->setLayout($inputBlock['o:layout']); diff --git a/application/src/Site/BlockLayout/Fallback.php b/application/src/Site/BlockLayout/Fallback.php index 76d75feea..23b23021c 100644 --- a/application/src/Site/BlockLayout/Fallback.php +++ b/application/src/Site/BlockLayout/Fallback.php @@ -5,6 +5,7 @@ use Omeka\Api\Representation\SitePageRepresentation; use Omeka\Api\Representation\SitePageBlockRepresentation; use Omeka\Stdlib\Message; +use Laminas\Form\Element; use Laminas\View\Renderer\PhpRenderer; class Fallback extends AbstractBlockLayout @@ -34,7 +35,10 @@ public function getLabel() public function form(PhpRenderer $view, SiteRepresentation $site, SitePageRepresentation $page = null, SitePageBlockRepresentation $block = null ) { - return $view->translate('This layout is invalid.'); + // Preserve the original data. + $element = new Element\Hidden("o:block[__blockIndex__][o:data]"); + $element->setValue(json_encode($block->data())); + return $view->translate('This layout is invalid.') . $view->formElement($element); } public function render(PhpRenderer $view, SitePageBlockRepresentation $block)