function i18n_sync_node_translation_file_field in Internationalization 7
Sync a file or image field:
- file-id's (fid) are synced
- order of fid's is synced
- description, alt, title is kept if already existing, copied otherwise
Parameters
object $node the node whose changes are to be synced:
object $translation a node to which the changes need to be synced:
string $field field name:
1 call to i18n_sync_node_translation_file_field()
- i18n_sync_node_translation_default_field in i18n_sync/
i18n_sync.node.inc - Synchronize configurable field
File
- i18n_sync/
i18n_sync.node.inc, line 155 - Internationalization (i18n) package. Synchronization of translations
Code
function i18n_sync_node_translation_file_field($node, $translation, $field) {
if (isset($node->{$field}[$node->language])) {
// Build a copy of the existing files in the translation node
// indexed by fid for easy retrieval in the copy loop below
$existing_files = array();
if (isset($translation->{$field}[$translation->language])) {
foreach ($translation->{$field}[$translation->language] as $delta => $file) {
$existing_files[$file['fid']] = $file;
}
}
// Start creating the translated copy
$translated_files = $node->{$field}[$node->language];
foreach ($translated_files as $delta => &$file) {
// keep alt, title, description if they already exist
if (array_key_exists($file['fid'], $existing_files)) {
foreach (array(
'title',
'description',
'alt',
) as $property) {
if (!empty($existing_files[$file['fid']][$property])) {
$file[$property] = $existing_files[$file['fid']][$property];
}
}
}
}
$translation->{$field}[$translation->language] = $translated_files;
}
}