translation_node_prepare
- Versions
- 7
translation_node_prepare($node)
Implement hook_node_prepare().
Code
modules/translation/translation.module, line 190
<?php
function translation_node_prepare($node) {
// Only act if we are dealing with a content type supporting translations.
if (translation_supported_type($node->type)) {
if (empty($node->nid) && isset($_GET['translation']) && isset($_GET['language']) &&
($source_nid = $_GET['translation']) && ($language = $_GET['language']) &&
(user_access('translate content'))) {
// We are translating a node from a source node, so
// load the node to be translated and populate fields.
$source_node = node_load($source_nid);
// Ensure we don't have an existing translation in this language.
if (!empty($source_node->tnid)) {
$translations = translation_node_get_translations($source_node->tnid);
if (isset($translations[$language])) {
$languages = language_list();
drupal_set_message(t('A translation of %title in %language already exists, a new %type will be created instead of a translation.', array('%title' => $source_node->title[FIELD_LANGUAGE_NONE][0]['value'], '%language' => $languages[$language]->name, '%type' => $node->type)), 'error');
return;
}
}
$node->language = $language;
$node->translation_source = $source_node;
$node->title = $node->translation_source->title;
// Let every module add custom translated fields.
module_invoke_all('node_prepare_translation', $node);
}
}
}
?>Login or register to post comments 