protected function TestBase::translate in Workbench Moderation to Content Moderation 8.2
Returns, or creates, an entity translation.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to translate.
string $language: The translation language code.
Return value
ContentEntityInterface The translated entity.
Overrides MigrationTestTrait::translate
2 calls to TestBase::translate()
- TestBase::testMultipleRevisionsWithNewTranslation in tests/
src/ Functional/ TestBase.php - Migrates an entity with several revisions, one of which adds a translation.
- TestBase::testMultipleTranslatedMixedRevisions in tests/
src/ Functional/ TestBase.php - Migrates an entity with several revisions and translations.
File
- tests/
src/ Functional/ TestBase.php, line 105
Class
Namespace
Drupal\Tests\wbm2cm\FunctionalCode
protected function translate(ContentEntityInterface $entity, $language) {
if ($entity
->hasTranslation($language)) {
$translation = $entity
->getTranslation($language);
}
else {
$translation = $entity
->addTranslation($language)
->getTranslation($language);
$label_key = $entity
->getEntityType()
->getKey('label');
if ($label_key) {
$translation
->set($label_key, $this
->randomMachineName(16));
}
}
return $translation;
}