From 2e96b8eeb5adbc5d27532e70faa8958d937c34a6 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 6 Sep 2023 10:35:45 +0200 Subject: [PATCH] wip #6248 @0.25 --- src/app/Magic/Models/Translate.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/app/Magic/Models/Translate.php b/src/app/Magic/Models/Translate.php index 76c8bb3..46857db 100644 --- a/src/app/Magic/Models/Translate.php +++ b/src/app/Magic/Models/Translate.php @@ -140,22 +140,23 @@ class Translate extends CubistMagicTranslatableModel $default = $this->_defaultTranslations(); $all = $this->attributes; - - $content = json_decode($all['content_translatable'], true); - foreach ($default as $locale => $translations) { - foreach ($translations as $str => $translation) { - if (!$translation) { - continue; - } - $key = self::_encodeKey($str); - if (!isset($content[$locale][$key]) || !$content[$locale][$key]) { - $content[$locale][$key] = $translation; + if (isset($all['content_translatable'])) { + $content = json_decode($all['content_translatable'], true); + foreach ($default as $locale => $translations) { + foreach ($translations as $str => $translation) { + if (!$translation) { + continue; + } + $key = self::_encodeKey($str); + if (!isset($content[$locale][$key]) || !$content[$locale][$key]) { + $content[$locale][$key] = $translation; + } } } - } - $all['content_translatable'] = json_encode($content); - $this->setRawAttributes($all); + $all['content_translatable'] = json_encode($content); + $this->setRawAttributes($all); + } return parent::onSaving(); } @@ -172,6 +173,9 @@ class Translate extends CubistMagicTranslatableModel { $translations = []; $all = json_decode($this->getAttribute('content_translatable')); + if (null === $all) { + return; + } $locale = $this->locale; foreach ($all as $field => $content) { if ($content == '') { -- 2.39.5