You are here

protected function EntityProcessorBase::getEntityTranslations in Content Synchronizer 3.x

Same name and namespace in other branches
  1. 8.2 src/Processors/Entity/EntityProcessorBase.php \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase::getEntityTranslations()
  2. 8 src/Processors/Entity/EntityProcessorBase.php \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase::getEntityTranslations()

Return the entity translations.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

array|\Drupal\Core\Language\LanguageInterface[] The array of translations.

2 calls to EntityProcessorBase::getEntityTranslations()
EntityProcessorBase::export in src/Processors/Entity/EntityProcessorBase.php
Export the entity and return the gid if exists, else false.
EntityProcessorBase::getEntityToImport in src/Processors/Entity/EntityProcessorBase.php
Return the entity to import.

File

src/Processors/Entity/EntityProcessorBase.php, line 182

Class

EntityProcessorBase
The entity processor base.

Namespace

Drupal\content_synchronizer\Processors\Entity

Code

protected function getEntityTranslations(EntityInterface $entity) {
  $translations = [];
  if ($entity instanceof TranslatableInterface) {
    foreach ($entity
      ->getTranslationLanguages() as $languageId => $data) {
      $translations[$languageId] = \Drupal::service('entity.repository')
        ->getTranslationFromContext($entity, $languageId);
    }
  }
  else {
    $defaultLangcode = $entity
      ->language()
      ->getId();
    $translations[$defaultLangcode] = \Drupal::service('entity.repository')
      ->getTranslationFromContext($entity, $defaultLangcode);
  }
  return array_filter($translations, function ($entity) {
    return $entity
      ->id();
  });
}