diff --git a/CHANGELOG.md b/CHANGELOG.md index 2386913d3e2..ff15efe80d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed a bug where element chips within thumbnail views weren’t getting light gray backgrounds. ([#15649](https://github.com/craftcms/cms/issues/15649)) - Fixed a bug where Link fields didn’t fully support inline editing. ([#15653](https://github.com/craftcms/cms/issues/15653)) - Fixed the loading spinner styling on element indexes. ([#15634](https://github.com/craftcms/cms/issues/15634)) +- Fixed an error that could occur when saving an element. ([#15656](https://github.com/craftcms/cms/issues/15656)) ## 5.4.0.1 - 2024-09-03 diff --git a/src/services/Elements.php b/src/services/Elements.php index d5b2adee703..8ad0edc5a21 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -57,6 +57,7 @@ use craft\helpers\Db; use craft\helpers\ElementHelper; use craft\helpers\Html; +use craft\helpers\Json; use craft\helpers\Queue; use craft\helpers\StringHelper; use craft\helpers\UrlHelper; @@ -3739,7 +3740,11 @@ private function _saveElementInternal( // if we're supposed to save all the content if ($saveContent || !empty($dirtyFields)) { - $oldContent = $siteSettingsRecord->content; // we'll need that if we're not saving all the content + $oldContent = $siteSettingsRecord->content ?? []; // we'll need that if we're not saving all the content + if (is_string($oldContent)) { + $oldContent = $oldContent !== '' ? Json::decode($oldContent) : []; + } + $content = []; if ($fieldLayout) { foreach ($fieldLayout->getCustomFields() as $field) {