You are here

function i18n_sync_node_prepare in Internationalization 7

Implements hook_node_prepare().

File

i18n_sync/i18n_sync.module, line 203
Internationalization (i18n) package. Synchronization of translations

Code

function i18n_sync_node_prepare($node) {

  // If creating a translation, copy over all the fields to be synchronized.
  if (empty($node->nid) && !empty($node->translation_source) && ($sync_fields = i18n_sync_node_fields($node->type))) {
    $source = $node->translation_source;
    $i18n_options = i18n_sync_node_options($node->type);

    // Copy over standard node fields. The rest are handled by field_attach_prepare_translation()
    foreach ($sync_fields as $field) {
      if (!empty($source->{$field}) && empty($i18n_options[$field]['field_name'])) {
        if ($field == 'uid') {
          $node->name = $source->name;
        }
        elseif ($field == 'created') {
          $node->date = format_date($source->created, 'custom', 'Y-m-d H:i:s O');
        }
        else {
          $node->{$field} = $source->{$field};
        }
      }
    }
  }
}