function field_attach_prepare_translation

Prepares an entity for translation.

This function is used to fill-in the form default values for Field API fields while performing entity translation. By default it copies all the source values in the given source language to the new entity and assigns them the target language.

This is used as part of the 'per entity' translation pattern, which is implemented only for nodes by translation.module. Other entity types may be supported through contributed modules.


$entity_type: The type of $entity; e.g. 'node' or 'user'.

$entity: The entity to be prepared for translation.

$langcode: The language the entity has to be translated in.

$source_entity: The source entity holding the field values to be translated.

$source_langcode: The source language from which translate.

Related topics

1 call to field_attach_prepare_translation()
translation_node_prepare in drupal/modules/translation/translation.module
Implements hook_node_prepare().


drupal/modules/field/, line 1315
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.


function field_attach_prepare_translation($entity_type, $entity, $langcode, $source_entity, $source_langcode) {
  $options = array(
    'language' => $langcode,

  // Copy source field values into the entity to be prepared.
  _field_invoke_default('prepare_translation', $entity_type, $entity, $source_entity, $source_langcode, $options);

  // Let field types handle their own advanced translation pattern if needed.
  _field_invoke('prepare_translation', $entity_type, $entity, $source_entity, $source_langcode, $options);

  // Let other modules alter the entity translation.
  $context = array(
    'entity_type' => $entity_type,
    'langcode' => $langcode,
    'source_entity' => $source_entity,
    'source_langcode' => $source_langcode,
  drupal_alter('field_attach_prepare_translation', $entity, $context);