You are here

public function ContentTranslationController::prepareTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/content_translation/src/Controller/ContentTranslationController.php \Drupal\content_translation\Controller\ContentTranslationController::prepareTranslation()

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.

1 call to ContentTranslationController::prepareTranslation()
ContentTranslationController::add in core/modules/content_translation/src/Controller/ContentTranslationController.php
Builds an add translation page.

File

core/modules/content_translation/src/Controller/ContentTranslationController.php, line 58
Contains \Drupal\content_translation\Controller\ContentTranslationController.

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);
}