field_attach_prepare_translation

function field_attach_prepare_translation

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

modules/field/field.attach.inc, line 1315
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,
  );
  drupal_alter('field_attach_prepare_translation', $entity, $context);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_prepare_translation/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部