Index: branches/5.1.x/core/kernel/db/dbitem.php =================================================================== diff -u -N -r14241 -r14408 --- branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 14241) +++ branches/5.1.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 14408) @@ -1,6 +1,6 @@ Prefix.'-cdata.'.$this->Special, '.'); - $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true, 'populate_ml_fields' => true)); + $cdata_key = rtrim($this->Prefix . '-cdata.' . $this->Special, '.'); + $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true)); + /* @var $cdata kDBItem */ + $resource_id = $this->GetDBField('ResourceId'); $cdata->Load($resource_id, 'ResourceId'); $cdata->SetDBField('ResourceId', $resource_id); $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); /* @var $ml_formatter kMultiLanguage */ + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + foreach ($this->customFields as $custom_id => $custom_name) { - $force_primary = isset($cdata->Fields['cust_'.$custom_id]['force_primary']) && $cdata->Fields['cust_'.$custom_id]['force_primary']; - $cdata->SetDBField($ml_formatter->LangFieldName('cust_'.$custom_id, $force_primary), $this->GetDBField('cust_'.$custom_name)); + $field_options = $cdata->GetFieldOptions('cust_' . $custom_id); + $force_primary = isset($field_options['force_primary']) && $field_options['force_primary']; + + if ($force_primary) { + $cdata->SetDBField($ml_formatter->LangFieldName('cust_' . $custom_id, true), $this->GetDBField('cust_' . $custom_name)); + } + else { + for ($language_id = 1; $language_id <= $ml_helper->languageCount; $language_id++) { + if (!$ml_helper->LanguageFound($language_id)) { + continue; + } + + $cdata->SetDBField('l' . $language_id . '_cust_' . $custom_id, $this->GetDBField('l' . $language_id . '_cust_' . $custom_name)); + } + } } return $cdata->isLoaded() ? $cdata->Update() : $cdata->Create();