protected ContentEntityBase::initializeTranslation($langcode)
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.
File
- core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 772
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; return $translation; }
Please login to continue.