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

8.0.x
Alex Pott 2015-02-08 00:02:31 +00:00
parent 91ae64ac59
commit 42083a1cc7
2 changed files with 27 additions and 2 deletions

View File

@ -650,9 +650,9 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
$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;
}

View File

@ -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 @@ class EntityTranslationTest extends EntityLanguageTestBase {
}
}
/**
* 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)));
}
}
}