protected function ContentEntityStorageBase::invokeTranslationHooks

protected ContentEntityStorageBase::invokeTranslationHooks(ContentEntityInterface $entity)

Checks translation statuses and invoke the related hooks if needed.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being saved.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 361

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function invokeTranslationHooks(ContentEntityInterface $entity) {
  $translations = $entity->getTranslationLanguages(FALSE);
  $original_translations = $entity->original->getTranslationLanguages(FALSE);
  $all_translations = array_keys($translations + $original_translations);

  // Notify modules of translation insertion/deletion.
  foreach ($all_translations as $langcode) {
    if (isset($translations[$langcode]) && !isset($original_translations[$langcode])) {
      $this->invokeHook('translation_insert', $entity->getTranslation($langcode));
    }
    elseif (!isset($translations[$langcode]) && isset($original_translations[$langcode])) {
      $this->invokeHook('translation_delete', $entity->original->getTranslation($langcode));
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityStorageBase.php/function/ContentEntityStorageBase::invokeTranslationHooks/8.1.x