function translation_entity_entity_insert

Implements hook_entity_insert().

1 call to translation_entity_entity_insert()
translation_entity_entity_update in drupal/core/modules/translation_entity/translation_entity.module
Implements hook_entity_update().

File

drupal/core/modules/translation_entity/translation_entity.module, line 503
Allows entities to be translated into different languages.

Code

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();
}