$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();
}
{
$translations = [];
$all = json_decode($this->getAttribute('content_translatable'));
+ if (null === $all) {
+ return;
+ }
$locale = $this->locale;
foreach ($all as $field => $content) {
if ($content == '') {