]> _ Git - cubist_cms-back.git/commitdiff
wip #6248 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 08:35:45 +0000 (10:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 08:35:45 +0000 (10:35 +0200)
src/app/Magic/Models/Translate.php

index 76c8bb3cf54275ca345dd6ddecb94ea53dab17fb..46857db84e675a0631c7a3d503b4a1d4a674aa53 100644 (file)
@@ -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 == '') {