function TranslatableInterface::addTranslation

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TypedData/TranslatableInterface.php \Drupal\Core\TypedData\TranslatableInterface::addTranslation()
  2. 8.9.x core/lib/Drupal/Core/TypedData/TranslatableInterface.php \Drupal\Core\TypedData\TranslatableInterface::addTranslation()
  3. 10 core/lib/Drupal/Core/TypedData/TranslatableInterface.php \Drupal\Core\TypedData\TranslatableInterface::addTranslation()

Adds a new translation to the translatable object.

To create a translation of an entity prefilled with the original data:

$entity->addTranslation($langcode, $entity->toArray());

Parameters

string $langcode: The language code identifying the translation.

array $values: (optional) An array of initial values to be assigned to the translatable fields. Defaults to none.

Return value

static A new entity translation object.

Throws

\InvalidArgumentException If an invalid or existing translation language is specified.

File

core/lib/Drupal/Core/TypedData/TranslatableInterface.php, line 119

Class

TranslatableInterface
Interface for translatable data.

Namespace

Drupal\Core\TypedData

Code

public function addTranslation($langcode, array $values = []);

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