i18nsync_node_translation($node, $translation, $fields, $op)
contributions/i18n/i18nsync/i18nsync.module, line 185
Synchronizes fields for node translation
There's some specific handling for known fields like:
$node Source node being edited
$translation Node translation to synchronize, just needs nid property
$fields List of fields to synchronize
$op Node operation (insert|update)
<?php
function i18nsync_node_translation($node, $translation, $fields, $op) {
// Load full node, we need all data here
$translation = node_load($translation->nid);
foreach ($fields as $field) {
switch($field) {
case 'taxonomy': // Do nothing it has already been syncd
i18nsync_taxonomyfield($translation, $node);
break;
case 'parent': // Book outlines, translating parent page if exists
case 'iid': // Attached image nodes
i18nsync_node_translation_attached_node($node, $translation, $field);
break;
case 'files':
// Sync existing attached files
foreach ($node->files as $fid => $file) {
if (isset($translation->files[$fid])) {
$translation->files[$fid]->list = $file->list;
} else {
// New file. Create new revision of file for the translation
$translation->files[$fid] = $file;
// If it's a new node revision it will just be created, but if it's not
// we have to update the table directly. The revision field was before this one in the list
if (!isset($translation->revision) || !$translation->revision) {
db_query("INSERT INTO {upload} (fid, nid, vid, list, description) VALUES (%d, %d, %d, %d, '%s')", $file->fid, $translation->nid, $translation->vid, $file->list, $file->description);
}
}
}
// Drop removed files
foreach ($translation->files as $fid => $file) {
if (!isset($node->files[$fid])) {
$translation->files[$fid]->remove = TRUE;
}
}
break;
default: // For fields that don't need special handling
if (isset($node->$field)) {
$translation->$field = $node->$field;
}
}
}
node_save($translation);
}
?>