Implements hook_entity_insert().
function translation_entity_entity_insert(EntityInterface $entity) {
// Only do something if translation support for the given entity is enabled.
if (!$entity
->isTranslatable()) {
return;
}
$fields = array(
'entity_type',
'entity_id',
'langcode',
'source',
'outdated',
'uid',
'status',
'created',
'changed',
);
$query = db_insert('translation_entity')
->fields($fields);
foreach ($entity
->getTranslationLanguages() as $langcode => $language) {
$translation = isset($entity->translation[$langcode]) ? $entity->translation[$langcode] : array();
$translation += array(
'source' => '',
'uid' => $GLOBALS['user']->uid,
'outdated' => FALSE,
'status' => TRUE,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
);
$translation['entity_type'] = $entity
->entityType();
$translation['entity_id'] = $entity
->id();
$translation['langcode'] = $langcode;
// Reorder values to match the schema.
$values = array();
foreach ($fields as $field_name) {
$value = is_bool($translation[$field_name]) ? intval($translation[$field_name]) : $translation[$field_name];
$values[$field_name] = $value;
}
$query
->values($values);
}
$query
->execute();
}