1 field.attach.inc field_attach_prepare_translation($entity_type, $entity, $langcode, $source_entity, $source_langcode)

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.

Parameters

$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

File

core/modules/field/field.attach.inc, line 1269
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.

Code

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,
  );
  backdrop_alter('field_attach_prepare_translation', $entity, $context);
}