function translation_node_insert

Implements hook_node_insert().

File

modules/translation/translation.module, line 323

Code

function translation_node_insert($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;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.