Index: trunk/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r8545 -r8563 --- trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 8545) +++ trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 8563) @@ -1024,7 +1024,10 @@ if ($formatter_class == 'kMultiLanguage') { $formatter =& $this->Application->recallObject($formatter_class); - $field = $formatter->LangFieldName($field); + /* @var $formatter kMultiLanguage */ + + $force_primary = isset($object->Fields[$field]['force_primary']) && $object->Fields[$field]['force_primary']; + $field = $formatter->LangFieldName($field, $force_primary); } $id_field = getArrayValue($params, 'IdField'); Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -N -r8481 -r8563 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8481) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 8563) @@ -979,15 +979,18 @@ } $cdata_key = rtrim($this->Prefix.'-cdata.'.$this->Special, '.'); - $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true)); + $cdata =& $this->Application->recallObject($cdata_key, null, Array('skip_autoload' => true, 'populate_ml_fields' => true)); $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 */ + foreach ($this->customFields as $custom_id => $custom_name) { - $cdata->SetDBField($ml_formatter->LangFieldName('cust_'.$custom_id), $this->GetDBField('cust_'.$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)); } if ($cdata->isLoaded()) { Index: trunk/core/units/custom_data/custom_data_event_handler.php =================================================================== diff -u -N -r8397 -r8563 --- trunk/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 8397) +++ trunk/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 8563) @@ -5,34 +5,34 @@ /** * [HOOK] Allows to apply custom fields functionality to specific config * When main item is created, then cdata config is cloned - * + * * @param kEvent $event */ function OnDefineCustomFields(&$event) { // 1. clone customdata table $clones = $this->Application->getUnitOption('cdata', 'Clones'); $clones[$event->MasterEvent->Prefix.'-cdata'] = Array ( - 'ParentPrefix' => $event->MasterEvent->Prefix, + 'ParentPrefix' => $event->MasterEvent->Prefix, 'TableName' => $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TableName').'CustomData', ); $this->Application->setUnitOption('cdata', 'Clones', $clones); - + // 2. add custom field information to main item $this->createCustomFields($event->MasterEvent->Prefix); } - + function scanCustomFields($prefix) { if (defined('IS_INSTALL') && IS_INSTALL && !$this->Application->TableFound('CustomField')) { return false; } - + if (!$prefix) { // prefix not specified return false; } - + $item_type = $this->Application->getUnitOption($prefix, 'ItemType'); if (!$item_type) { // no main config of such type @@ -49,10 +49,10 @@ // config doesn't have custom fields return false; } - + return $custom_fields; } - + /** * Fills cloned cdata config with data from it's parent * @@ -61,7 +61,7 @@ function OnAfterConfigRead(&$event) { $main_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - + $custom_fields = $this->scanCustomFields($main_prefix); if (!$custom_fields) { return false; @@ -73,10 +73,11 @@ foreach ($custom_fields as $custom_id => $custom_params) { if (isset($fields['cust_'.$custom_id])) continue; $fields['cust_'.$custom_id] = $field_options; + $fields['cust_'.$custom_id]['force_primary'] = !$custom_params['MultiLingual']; } $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); } - + /** * Creates "cust_" virtual fields for main item * @@ -88,13 +89,14 @@ if (!$custom_fields) { return false; } - + $calculated_fields = Array(); $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array()); $cf_helper =& $this->Application->recallObject('InpCustomFieldsHelper'); $field_options = Array('type' => 'string', 'not_null' => 1, 'default' => ''); $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + /* @var $ml_formatter kMultiLanguage */ foreach ($custom_fields as $custom_id => $custom_params) { switch ($custom_params['ElementType']) { @@ -119,7 +121,7 @@ } $custom_name = $custom_params['FieldName']; - $calculated_fields['cust_'.$custom_name] = 'cust.'.$ml_formatter->LangFieldName('cust_'.$custom_id); + $calculated_fields['cust_'.$custom_name] = 'cust.'.$ml_formatter->LangFieldName('cust_'.$custom_id, !$custom_params['MultiLingual']); if (!isset($virtual_fields['cust_'.$custom_name])) { $virtual_fields['cust_'.$custom_name] = Array(); }