protected function ContentEntityBase::initializeTranslation

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityBase.php/function/ContentEntityBase::initializeTranslation/8.1.x