Issue #2414721 by jesperjb, plach: EntityAdapter should be instantiated per language
parent
91ae64ac59
commit
42083a1cc7
|
@ -650,9 +650,9 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
|
||||||
$translation->translations = &$this->translations;
|
$translation->translations = &$this->translations;
|
||||||
$translation->enforceIsNew = &$this->enforceIsNew;
|
$translation->enforceIsNew = &$this->enforceIsNew;
|
||||||
$translation->translationInitialize = FALSE;
|
$translation->translationInitialize = FALSE;
|
||||||
// The label is the only entity key that can change based on the language,
|
// Reset language-dependent properties.
|
||||||
// so unset that in case it is currently set.
|
|
||||||
unset($translation->entityKeys['label']);
|
unset($translation->entityKeys['label']);
|
||||||
|
$translation->typedData = NULL;
|
||||||
|
|
||||||
return $translation;
|
return $translation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\system\Tests\Entity;
|
namespace Drupal\system\Tests\Entity;
|
||||||
|
|
||||||
|
use Drupal\Component\Utility\String;
|
||||||
use Drupal\Core\Language\LanguageInterface;
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
use Drupal\entity_test\Entity\EntityTestMulRev;
|
use Drupal\entity_test\Entity\EntityTestMulRev;
|
||||||
use Drupal\language\Entity\ConfigurableLanguage;
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue