function i18nsync_node_translation in Internationalization 5.3
Same name and namespace in other branches
- 5 experimental/i18nsync.module \i18nsync_node_translation()
- 5.2 experimental/i18nsync.module \i18nsync_node_translation()
- 6 i18nsync/i18nsync.module \i18nsync_node_translation()
1 call to i18nsync_node_translation()
- i18nsync_nodeapi in experimental/
i18nsync.module - Implementation of hook_nodeapi().
File
- experimental/
i18nsync.module, line 136 - Internationalization (i18n) package. Synchronization of translations
Code
function i18nsync_node_translation($node, $translation, $fields) {
// Load full node, we need all data here
$translation = node_load($translation->nid);
foreach ($fields as $field) {
switch ($field) {
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 {file_revisions} (fid, vid, list, description) VALUES (%d, %d, %d, '%s')", $file->fid, $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);
}