You are here

function node_reference_field_prepare_translation in References 7.2

Implements hook_field_prepare_translation().

When preparing a translation, load any translations of existing references.

File

node_reference/node_reference.module, line 1053
Defines a field type for referencing one node from another.

Code

function node_reference_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) {
  if (isset($items) && is_array($items)) {

    // Match each reference with its matching translation, if it exists.
    foreach ($items as $key => $item) {
      $reference_node = node_load($item['nid']);
      $items[$key]['nid'] = node_reference_find_translation($reference_node, $entity->language);
    }
  }
}