1 translation.module | translation_node_insert(Node $node) |
Implements hook_node_insert().
File
- core/
modules/ translation/ translation.module, line 373 - Manages content translations.
Code
function translation_node_insert(Node $node) {
// Only act if we are dealing with a content type supporting translations.
if (translation_supported_type($node->type)) {
if (!empty($node->translation_source)) {
if ($node->translation_source->tnid) {
// Add node to existing translation set.
$tnid = $node->translation_source->tnid;
}
else {
// Create new translation set, using nid from the source node.
$tnid = $node->translation_source->nid;
db_update('node')
->fields(array(
'tnid' => $tnid,
'translate' => 0,
))
->condition('nid', $tnid)
->execute();
// Flush the (untranslated) source node from the load cache.
entity_get_controller('node')->resetCache(array($tnid));
}
db_update('node')
->fields(array(
'tnid' => $tnid,
'translate' => 0,
))
->condition('nid', $node->nid)
->execute();
// Save tnid to avoid loss in case of resave.
$node->tnid = $tnid;
}
}
}