public ContentTranslationController::prepareTranslation(ContentEntityInterface $entity, LanguageInterface $source, LanguageInterface $target)
Populates target values with the source values.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being translated.
\Drupal\Core\Language\LanguageInterface $source: The language to be used as source.
\Drupal\Core\Language\LanguageInterface $target: The language to be used as target.
File
- core/modules/content_translation/src/Controller/ContentTranslationController.php, line 53
Class
- ContentTranslationController
- Base class for entity translation controllers.
Namespace
Drupal\content_translation\Controller
Code
public function prepareTranslation(ContentEntityInterface $entity, LanguageInterface $source, LanguageInterface $target) {
/* @var \Drupal\Core\Entity\ContentEntityInterface $source_translation */
$source_translation = $entity->getTranslation($source->getId());
$target_translation = $entity->addTranslation($target->getId(), $source_translation->toArray());
// Make sure we do not inherit the affected status from the source values.
if ($entity->getEntityType()->isRevisionable()) {
$target_translation->setRevisionTranslationAffected(NULL);
}
/** @var \Drupal\user\UserInterface $user */
$user = $this->entityManager()->getStorage('user')->load($this->currentUser()->id());
$metadata = $this->manager->getTranslationMetadata($target_translation);
// Update the translation author to current user, as well the translation
// creation time.
$metadata->setAuthor($user);
$metadata->setCreatedTime(REQUEST_TIME);
}
Please login to continue.