function i18n_menu_node_translation in Menu translation - Node 7
Return the nid of the node translation for the given language if available.
1 call to i18n_menu_node_translation()
- i18n_menu_node_translated_menu_link_alter in ./
i18n_menu_node.module - Implementation of hook_translated_menu_link_alter().
File
- ./
i18n_menu_node.module, line 273 - Menu translation (Node).
Code
function i18n_menu_node_translation($item, $map, $langcode = NULL) {
if (empty($item['options']['translations'])) {
return FALSE;
}
// If the current item is also the active item, in $map[1] we have a node
// object instead of a simple nid.
$nid = is_object($map[1]) ? $map[1]->nid : $map[1];
if (empty($langcode)) {
// Retrieve the current language.
$langcode = i18n_language()->language;
}
// If the translation is available, is not the current element and translation
// support for its node type is enabled, we can use it.
// For performance reasons we check only if the node status is published or
// if the user can see unpublished nodes. Uncommon cases of fine-grained
// access-controlled translated node menu items might lead to "access denied"
// pages.
$translations = $item['options']['translations'];
if (is_array($translations) && isset($translations[$langcode])) {
$translation = $translations[$langcode];
if ($translation->nid != $nid && translation_supported_type($translation->type) && ($translation->status || user_access('administer nodes'))) {
return $translations[$langcode]->nid;
}
}
return FALSE;
}