You are here

function hook_lingotek_content_entity_translation_presave in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  2. 4.0.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  3. 3.0.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  4. 3.1.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  5. 3.2.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  6. 3.3.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  7. 3.4.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  8. 3.5.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  9. 3.6.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  10. 3.7.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()
  11. 3.8.x lingotek.api.php \hook_lingotek_content_entity_translation_presave()

Act on a translation of an content entity before it is saved or updated after being downloaded from Lingotek.

Parameters

\Drupal\Core\Entity\ContentEntityInterface &$translation: The content entity that is going to be saved.

string $langcode: Drupal language code that has been downloaded.

array $data: Data returned from the Lingotek service when asking for the translation.

Related topics

1 function implements hook_lingotek_content_entity_translation_presave()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

lingotek_test_lingotek_content_entity_translation_presave in tests/modules/lingotek_test/lingotek_test.module
Implements hook_lingotek_content_entity_translation_presave().
1 invocation of hook_lingotek_content_entity_translation_presave()
LingotekContentTranslationService::saveTargetData in src/LingotekContentTranslationService.php
Save the entity translation.

File

./lingotek.api.php, line 33

Code

function hook_lingotek_content_entity_translation_presave(ContentEntityInterface &$translation, $langcode, $data) {

  // In this example, we avoid press releases to be published when downloaded.
  if ($translation
    ->getEntityTypeId() === 'node' && $translation
    ->bundle() === 'press_release') {
    if ($translation
      ->isNewTranslation()) {

      /** @var \Drupal\node\NodeInterface $translation */
      $translation
        ->setPublished(FALSE);
    }
  }
}