You are here

function field_collection_tmgmt_source_translation_structure in Translation Management Tool 7

Implements hook_tmgmt_source_translation_structure().

This hook is implemented on behalf of the field_collection module.

File

sources/field/tmgmt_field.field_collection.inc, line 12
Enable tmgmt_field to translate field collections

Code

function field_collection_tmgmt_source_translation_structure($entity_type, $entity, $field, $instance, $langcode, $items) {
  $fields = array();
  $fields['#label'] = check_plain($instance['label']);
  $sub_fields = field_info_instances('field_collection_item', $field['field_name']);
  foreach ($items as $delta => $item) {
    $field_collection_instance = field_collection_item_load($item['value']);
    if (count($items) > 1) {
      $fields[$delta]['#label'] = t('Delta #@delta', array(
        '@delta' => $delta,
      ));
    }
    foreach ($sub_fields as $sub_field_name => $sub_field_instance) {
      $sub_field = field_info_field($sub_field_name);
      $sub_field_items = field_get_items('field_collection_item', $field_collection_instance, $sub_field_name, $langcode);
      if ($items) {
        $sub_field_data = module_invoke($sub_field['module'], 'tmgmt_source_translation_structure', 'field_collection_item', $field_collection_instance, $sub_field, $sub_field_instance, $langcode, $sub_field_items);
        if ($sub_field_data) {
          $fields[$delta][$sub_field_name] = $sub_field_data;
        }
      }
    }
  }
  return $fields;
}