You are here

function lingotek_process_field_collection_xml in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.remote.inc \lingotek_process_field_collection_xml()
1 call to lingotek_process_field_collection_xml()
lingotek_process_entity_xml in ./lingotek.remote.inc

File

./lingotek.remote.inc, line 311

Code

function lingotek_process_field_collection_xml($xml, $entity_type, &$entity, $field_name, $delta, $langcode, $node_based_translation) {
  $field_info = field_info_field($field_name);
  $curr_field_data =& $entity->{$field_name};
  $default = language_default();
  $default_language = $default->language;
  if (isset($curr_field_data[LANGUAGE_NONE][$delta]['value'])) {
    $field_collection_id = $curr_field_data[LANGUAGE_NONE][$delta]['value'];
  }
  elseif (isset($curr_field_data[$default_language][$delta]['value'])) {
    $field_collection_id = $curr_field_data[$default_language][$delta]['value'];
  }
  else {
    if (!$node_based_translation) {

      // The field-collection field must be empty.
      return;
    }

    // If it does not exist and the profile is node-based, create a new FC.
    $field_collection_item = entity_create('field_collection_item', array(
      'field_name' => $field_info['field_name'],
    ));
    $field_collection_item
      ->setHostEntity($entity_type, $entity);
    $field_collection_item
      ->save();
    $field_collection_id = $field_collection_item->item_id;
  }
  $field_collection_item = lingotek_entity_load_single('field_collection_item', $field_collection_id);
  if (!$field_collection_item) {

    // The field collection was removed, so disregard any info on it
    return;
  }
  $field_collection_item->type = $field_info['field_name'];
  $field_collection_item->language = $entity->language;

  // RECURSION FOR FIELD COLLECTIONS
  lingotek_process_entity_xml($xml, $field_collection_item, 'field_collection_item', $langcode, $node_based_translation);
}