You are here

function translation_node_get_translations in Drupal 7

Same name and namespace in other branches
  1. 6 modules/translation/translation.module \translation_node_get_translations()

Gets all nodes in a given translation set.

Parameters

$tnid: The translation source nid of the translation set, the identifier of the node used to derive all translations in the set.

Return value

Array of partial node objects (nid, title, language) representing all nodes in the translation set, in effect all translations of node $tnid, including node $tnid itself. Because these are partial nodes, you need to node_load() the full node, if you need more properties. The array is indexed by language code.

7 calls to translation_node_get_translations()
translation_form_node_form_alter in modules/translation/translation.module
Implements hook_form_BASE_FORM_ID_alter() for node_form().
translation_language_switch_links_alter in modules/translation/translation.module
Implements hook_language_switch_links_alter().
translation_node_overview in modules/translation/translation.pages.inc
Page callback: Displays a list of a node's translations.
translation_node_prepare in modules/translation/translation.module
Implements hook_node_prepare().
translation_node_validate in modules/translation/translation.module
Implements hook_node_validate().

... See full list

File

modules/translation/translation.module, line 486
Manages content translations.

Code

function translation_node_get_translations($tnid) {
  if (is_numeric($tnid) && $tnid) {
    $translations =& drupal_static(__FUNCTION__, array());
    if (!isset($translations[$tnid])) {
      $translations[$tnid] = array();
      $result = db_select('node', 'n')
        ->fields('n', array(
        'nid',
        'type',
        'uid',
        'status',
        'title',
        'language',
      ))
        ->condition('n.tnid', $tnid)
        ->addTag('node_access')
        ->execute();
      foreach ($result as $node) {
        $langcode = entity_language('node', $node);
        $translations[$tnid][$langcode] = $node;
      }
    }
    return $translations[$tnid];
  }
}