function ContentEntityBase::initializeTranslation

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::initializeTranslation()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::initializeTranslation()
  3. 11.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::initializeTranslation()

Instantiates a translation object for an existing translation.

The translated entity will be a clone of the current entity with the specified $langcode. All translations share the same field data structures to ensure that all of them deal with fresh data.

Parameters

string $langcode: The language code for the requested translation.

Return value

\Drupal\Core\Entity\EntityInterface The translation object. The content properties of the translation object are stored as references to the main entity.

1 call to ContentEntityBase::initializeTranslation()
ContentEntityBase::getTranslation in core/lib/Drupal/Core/Entity/ContentEntityBase.php

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 901

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

protected function initializeTranslation($langcode) {
    // If the requested translation is valid, clone it with the current language
    // as the active language. The $translationInitialize flag triggers a
    // shallow (non-recursive) clone.
    $this->translationInitialize = TRUE;
    $translation = clone $this;
    $this->translationInitialize = FALSE;
    $translation->activeLangcode = $langcode;
    // Ensure that changes to fields, values and translations are propagated
    // to all the translation objects.
    // @todo Consider converting these to ArrayObject.
    $translation->values =& $this->values;
    $translation->fields =& $this->fields;
    $translation->translations =& $this->translations;
    $translation->enforceIsNew =& $this->enforceIsNew;
    $translation->newRevision =& $this->newRevision;
    $translation->entityKeys =& $this->entityKeys;
    $translation->translatableEntityKeys =& $this->translatableEntityKeys;
    $translation->translationInitialize = FALSE;
    $translation->typedData = NULL;
    $translation->loadedRevisionId =& $this->loadedRevisionId;
    $translation->isDefaultRevision =& $this->isDefaultRevision;
    $translation->enforceRevisionTranslationAffected =& $this->enforceRevisionTranslationAffected;
    $translation->isSyncing =& $this->isSyncing;
    return $translation;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.