Implements hook_entity_insert().
function translation_entity_entity_insert(EntityInterface $entity) {
// Only do something if translation support for the given entity is enabled.
if (!translation_entity_enabled($entity
->entityType(), $entity
->bundle())) {
return;
}
$entity_type = $entity
->entityType();
$id = $entity
->id();
$query = db_insert('translation_entity')
->fields(array(
'entity_type',
'entity_id',
'langcode',
'source',
'translate',
));
foreach ($entity
->getTranslationLanguages() as $langcode => $language) {
// @todo Declare these as entity (translation?) properties.
$source = (isset($entity->source[$langcode]) ? $entity->source[$langcode] : NULL) . '';
$retranslate = intval(!empty($entity->retranslate[$langcode]));
$query
->values(array(
$entity_type,
$id,
$langcode,
$source,
$retranslate,
));
}
$query
->execute();
}