function i18nsync_node_translation in Internationalization 6
Same name and namespace in other branches
- 5.3 experimental/i18nsync.module \i18nsync_node_translation()
- 5 experimental/i18nsync.module \i18nsync_node_translation()
- 5.2 experimental/i18nsync.module \i18nsync_node_translation()
Synchronizes fields for node translation.
There's some specific handling for known fields like:
- files, for file attachments.
- iid (CCK node attachments, translations for them will be handled too).
All the rest of the fields will be just copied over. The 'revision' field will have the special effect of creating a revision too for the translation.
Parameters
$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).
1 call to i18nsync_node_translation()
- i18nsync_nodeapi in i18nsync/
i18nsync.module - Implementation of hook_nodeapi().
File
- i18nsync/
i18nsync.module, line 262 - Internationalization (i18n) package. Synchronization of translations
Code
function i18nsync_node_translation($node, $translation, $fields, $op) {
// Load full node, we need all data here.
$translation = node_load($translation->nid, NULL, TRUE);
// Collect info on any CCK fields.
$content_fields = _i18nsync_cck_fields($node->type);
foreach ($fields as $field) {
// Check for CCK fields first.
if (isset($content_fields[$field]) && isset($node->{$field})) {
switch ($content_fields[$field]['type']) {
// TODO take type specific actions.
// Filefields and imagefields are syncronized equally.
case 'filefield':
case 'imagefield':
i18nsync_node_translation_filefield_field($node, $translation, $field);
break;
case 'nodereference':
i18nsync_node_translation_nodereference_field($node, $translation, $field);
break;
default:
// For fields that don't need special handling.
$translation->{$field} = $node->{$field};
}
// Skip over the regular handling.
continue;
}
else {
switch ($field) {
case 'taxonomy':
// Do nothing it has already been syncd.
i18nsync_node_taxonomy($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 'images':
$translation->images = $node->images;
// Intentional no break so 'images' synchronizes files too.
// About images, see related patch status: http://drupal.org/node/360643
// @todo Weird things may happen if 'images' and 'files' are both selected
case 'files':
// Sync existing attached files. This should work for images too
foreach ((array) $node->files as $fid => $file) {
if (isset($translation->files[$fid])) {
// Just update list and weight properties, description can be different
$translation->files[$fid]->list = $file->list;
$translation->files[$fid]->weight = $file->weight;
}
else {
// New file. Clone so we can set the new property just for this translation
$translation->files[$fid] = clone $file;
$translation->files[$fid]->new = TRUE;
}
}
// Drop removed files.
foreach ((array) $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);
}