You are here

function translation_nodeapi in Internationalization 5.2

Same name and namespace in other branches
  1. 5.3 translation/translation.module \translation_nodeapi()
  2. 5 translation/translation.module \translation_nodeapi()

Implementation of hook_nodeapi().

Delete case is now handled in i18n_nodeapi

File

translation/translation.module, line 270

Code

function translation_nodeapi(&$node, $op, $arg = 0) {
  if (variable_get("i18n_node_{$node->type}", 0)) {
    switch ($op) {
      case 'load':
        return array(
          'translation' => translation_node_get_translations(array(
            'nid' => $node->nid,
          ), FALSE),
        );
        break;
      case 'insert':
        if ($node->translation_nid) {

          // If not existing translation set, update both nodes. Otherwise trid is saved by i18n module
          if (!$node->trid) {
            $node->trid = db_next_id('{i18n_node}_trid');
            db_query("UPDATE {i18n_node} SET trid = %d WHERE nid=%d OR nid=%d", $node->trid, $node->nid, $node->translation_nid);
          }

          // Clone files for node attachments
          if (isset($node->translation_files)) {
            foreach ($node->translation_files as $fid => $file) {
              if (!$file['remove']) {

                // We are using revisions to have a file linked to different nodes, different descriptions
                db_query("INSERT INTO {file_revisions} (fid, vid, list, description) VALUES (%d, %d, %d, '%s')", $file['fid'], $node->vid, $file['list'], $file['description']);
              }
            }
          }
        }
        break;
      case 'prepare':

        // When creating a translation
        if (empty($node->nid) && isset($_GET['translation']) && is_numeric($_GET['translation']) && !empty($_GET['language'])) {

          // We are translating a node from a source node
          // Load the node to be translated and populate fields
          translation_node_prepare($node, $_GET['translation'], $_GET['language']);
        }
        break;
    }

    // Add nat integration
    if (module_exists('nat')) {
      translation_nodeapi_nat($node, $op);
    }
  }
}