You are here

function lingotek_entity_presave in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8 lingotek.module \lingotek_entity_presave()
  2. 8.2 lingotek.module \lingotek_entity_presave()
  3. 7.7 lingotek.module \lingotek_entity_presave()
  4. 7.4 lingotek.module \lingotek_entity_presave()
  5. 7.5 lingotek.module \lingotek_entity_presave()
  6. 7.6 lingotek.module \lingotek_entity_presave()
  7. 4.0.x lingotek.module \lingotek_entity_presave()
  8. 3.0.x lingotek.module \lingotek_entity_presave()
  9. 3.1.x lingotek.module \lingotek_entity_presave()
  10. 3.2.x lingotek.module \lingotek_entity_presave()
  11. 3.3.x lingotek.module \lingotek_entity_presave()
  12. 3.5.x lingotek.module \lingotek_entity_presave()
  13. 3.6.x lingotek.module \lingotek_entity_presave()
  14. 3.7.x lingotek.module \lingotek_entity_presave()
  15. 3.8.x lingotek.module \lingotek_entity_presave()

Implements hook_entity_presave().

File

./lingotek.module, line 59
Implements Drupal-related hooks for the Lingotek Translation module.

Code

function lingotek_entity_presave(EntityInterface $entity) {
  $configuration_service = \Drupal::service('lingotek.configuration');
  if ($entity instanceof ContentEntityInterface && $configuration_service
    ->isEnabled($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {
    if ($entity
      ->language() === $entity
      ->getUntranslated()
      ->language()) {
      if ($entity->lingotek_metadata->entity === NULL) {
        $metadata = LingotekContentMetadata::create();
        $metadata
          ->save();
        $entity->lingotek_metadata = $metadata;
      }
      $translation_service = \Drupal::service('lingotek.content_translation');
      $translation_service
        ->updateEntityHash($entity);
    }
  }
}