I need to access the id of the translated node, if available for any given node. nid is the node id. It would seem tnid would be the id of the translated node. However, that seem not be the case. How can I get that id? I tried to the following code, which did not work.
global $language;
$translations = translation_node_get_translations($node->tnid);
if ($translations[$language->language]) {
$tnode = node_load($translations[$language->language]->nid);
echo $tnode->nid;
}
Any suggestions?
I need tnid to create a custom translation-link. Thanks.
translation_node_get_translations($node->tnid);
Provides the array of all the corresponding language nodes. I did not realize it, but that's all I needed.
Drupal 8
$languages = $node->getTranslationLanguages();
$translations = [];
foreach ($languages as $langcode => $language) {
$translations[$langcode] = $node->getTranslation($langcode);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With