You are here

function node_reference_find_translation in References 7.2

Find a translation for a specific node reference, if it exists.

Parameters

object $reference_node: The untranslated node reference.

string $langcode: String with lang code.

Return value

int A nid for the translation of the node reference, otherwise the original untranslated nid if no translation exists.

1 call to node_reference_find_translation()
node_reference_field_prepare_translation in node_reference/node_reference.module
Implements hook_field_prepare_translation().

File

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

Code

function node_reference_find_translation($reference_node, $langcode) {

  // Check if the source node translation is set and if translations are
  // supported.
  if (isset($reference_node->tnid) && translation_supported_type($reference_node->type)) {

    // Determine whether an alternative language is being used.
    if (!empty($reference_node->language) && $reference_node->language != $langcode) {

      // Return a corresponding translation nid for the reference
      // (if it exists).
      $translations = translation_node_get_translations($reference_node->tnid);
      if (isset($translations[$langcode])) {
        return $translations[$langcode]->nid;
      }
    }
  }

  // Return the untranslated reference nid, no matching translations found.
  return $reference_node->nid;
}