Commit 42083a1c authored by alexpott's avatar alexpott

Issue #2414721 by jesperjb, plach: EntityAdapter should be instantiated per language

parent 91ae64ac
......@@ -650,9 +650,9 @@ protected function initializeTranslation($langcode) {
$translation->translations = &$this->translations;
$translation->enforceIsNew = &$this->enforceIsNew;
$translation->translationInitialize = FALSE;
// The label is the only entity key that can change based on the language,
// so unset that in case it is currently set.
// Reset language-dependent properties.
unset($translation->entityKeys['label']);
$translation->typedData = NULL;
return $translation;
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Entity;
use Drupal\Component\Utility\String;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -665,4 +666,28 @@ protected function doTestLanguageChange($entity_type) {
}
}
/**
* Tests how entity adapters work with translations.
*/
function testEntityAdapter() {
$entity_type = 'entity_test';
$default_langcode = 'en';
$values[$default_langcode] = array('name' => $this->randomString());
$controller = $this->entityManager->getStorage($entity_type);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $controller->create($values[$default_langcode]);
foreach ($this->langcodes as $langcode) {
$values[$langcode] = array('name' => $this->randomString());
$entity->addTranslation($langcode, $values[$langcode]);
}
$langcodes = array_merge(array($default_langcode), $this->langcodes);
foreach ($langcodes as $langcode) {
$adapter = $entity->getTranslation($langcode)->getTypedData();
$name = $adapter->get('name')->value;
$this->assertEqual($name, $values[$langcode]['name'], String::format('Name correctly retrieved from "@langcode" adapter', array('@langcode' => $langcode)));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment