public function ContentEntityStorageBase::createTranslation
public ContentEntityStorageBase::createTranslation(ContentEntityInterface $entity, $langcode, array $values = [])
Constructs a new entity translation object, without permanently saving it.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity object being translated.
string $langcode: The translation language code.
array $values: (optional) An associative array of initial field values keyed by field name. If none is provided default values will be applied.
Return value
\Drupal\Core\Entity\ContentEntityInterface A new entity translation object.
Overrides ContentEntityStorageInterface::createTranslation
File
- core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 130
Class
- ContentEntityStorageBase
- Base class for content entity storage handlers.
Namespace
Drupal\Core\EntityCode
public function createTranslation(ContentEntityInterface $entity, $langcode, array $values = []) { $translation = $entity->getTranslation($langcode); $definitions = array_filter($translation->getFieldDefinitions(), function(FieldDefinitionInterface $definition) { return $definition->isTranslatable(); }); $field_names = array_map(function(FieldDefinitionInterface $definition) { return $definition->getName(); }, $definitions); $values[$this->langcodeKey] = $langcode; $values[$this->getEntityType()->getKey('default_langcode')] = FALSE; $this->initFieldValues($translation, $values, $field_names); $this->invokeHook('translation_create', $translation); 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!ContentEntityStorageBase.php/function/ContentEntityStorageBase::createTranslation/8.1.x