You are here

function i18n_sync_field_translation_sync in Internationalization 7

Synchronize entity field translation

1 call to i18n_sync_field_translation_sync()
i18n_sync_node_translation in i18n_sync/i18n_sync.node.inc
Synchronizes fields for node translation.

File

i18n_sync/i18n_sync.module, line 276
Internationalization (i18n) package. Synchronization of translations

Code

function i18n_sync_field_translation_sync($entity_type, $bundle_name, $entity, $langcode, $source_entity, $source_langcode, $field_name) {
  $field = field_info_field($field_name);
  $instance = field_info_instance($entity_type, $field_name, $bundle_name);
  $source_lang = field_language($entity_type, $source_entity, $field_name);
  $translation_lang = field_is_translatable($entity_type, $field) ? $entity->language : LANGUAGE_NONE;
  if (isset($source_entity->{$field_name}[$source_lang])) {
    $items = $source_entity->{$field_name}[$source_lang];

    // Determine the function to synchronize this field. If none, just copy over.
    $type_info = field_info_field_types($field['type']);
    if (isset($type_info['i18n_sync_callback'])) {
      $function = $type_info['i18n_sync_callback'];
      $function($entity_type, $entity, $field, $instance, $langcode, $items, $source_entity, $source_langcode);
    }
    $entity->{$field_name}[$translation_lang] = $items;
  }
  else {

    // If source not set, unset translation too
    unset($entity->{$field_name}[$translation_lang]);
  }
}