You are here

protected function MigrationTestTrait::translate in Workbench Moderation to Content Moderation 8.2

Translates an entity into every available language.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to translate.

Return value

string[] Every language into which the entity has been translated.

1 method overrides MigrationTestTrait::translate()
TestBase::translate in tests/src/Functional/TestBase.php
Returns, or creates, an entity translation.

File

tests/src/Kernel/MigrationTestTrait.php, line 58

Class

MigrationTestTrait

Namespace

Drupal\Tests\wbm2cm\Kernel

Code

protected function translate(ContentEntityInterface $entity) {
  $label_key = $entity
    ->getEntityType()
    ->getKey('label');
  $translation_languages = array_keys($entity
    ->getTranslationLanguages());
  $needed_languages = $this->container
    ->get('entity_type.manager')
    ->getStorage('configurable_language')
    ->getQuery()
    ->condition('locked', FALSE)
    ->condition('id', $translation_languages, 'NOT IN')
    ->execute();
  foreach ($needed_languages as $language) {
    $entity
      ->addTranslation($language)
      ->getTranslation($language)
      ->set($label_key, $this
      ->randomMachineName());
    array_push($translation_languages, $language);
  }
  return $translation_languages;
}