Issue #2939795 by plach, Wim Leers: Multilingual logic is not applied when a new revision translation is being added
parent
c9392bb311
commit
27700fa129
|
@ -152,6 +152,23 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
|
||||||
/**
|
/**
|
||||||
* Checks whether any entity revision is translated.
|
* Checks whether any entity revision is translated.
|
||||||
*
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\TranslatableInterface $entity
|
||||||
|
* The entity object to be checked.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* TRUE if the entity has at least one translation in any revision, FALSE
|
||||||
|
* otherwise.
|
||||||
|
*
|
||||||
|
* @see \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages()
|
||||||
|
* @see \Drupal\Core\Entity\ContentEntityStorageBase::isAnyStoredRevisionTranslated()
|
||||||
|
*/
|
||||||
|
protected function isAnyRevisionTranslated(TranslatableInterface $entity) {
|
||||||
|
return $entity->getTranslationLanguages(FALSE) || $this->isAnyStoredRevisionTranslated($entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether any stored entity revision is translated.
|
||||||
|
*
|
||||||
* A revisionable entity can have translations in a pending revision, hence
|
* A revisionable entity can have translations in a pending revision, hence
|
||||||
* the default revision may appear as not translated. This determines whether
|
* the default revision may appear as not translated. This determines whether
|
||||||
* the entity has any translation in the storage and thus should be considered
|
* the entity has any translation in the storage and thus should be considered
|
||||||
|
@ -165,8 +182,9 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*
|
*
|
||||||
* @see \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages()
|
* @see \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages()
|
||||||
|
* @see \Drupal\Core\Entity\ContentEntityStorageBase::isAnyRevisionTranslated()
|
||||||
*/
|
*/
|
||||||
protected function isAnyRevisionTranslated(TranslatableInterface $entity) {
|
protected function isAnyStoredRevisionTranslated(TranslatableInterface $entity) {
|
||||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||||
if ($entity->isNew()) {
|
if ($entity->isNew()) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -359,12 +359,20 @@ class EntityDecoupledTranslationRevisionsTest extends EntityKernelTestBase {
|
||||||
$previous_label = NULL;
|
$previous_label = NULL;
|
||||||
if (!$entity->isNewTranslation()) {
|
if (!$entity->isNewTranslation()) {
|
||||||
$previous_label = $this->generateNewEntityLabel($entity, $previous_revision_id);
|
$previous_label = $this->generateNewEntityLabel($entity, $previous_revision_id);
|
||||||
|
$latest_affected_revision_id = $this->storage->getLatestTranslationAffectedRevisionId($entity->id(), $entity->language()->getId());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Normally it would make sense to load the default revision in this
|
||||||
|
// case, however that would mean simulating here the logic that we need
|
||||||
|
// to test, thus "masking" possible flaws. To avoid that, we simply
|
||||||
|
// pretend we are starting from an earlier non translated revision.
|
||||||
|
// This ensures that the we can check that the merging logic is applied
|
||||||
|
// also when adding a new translation.
|
||||||
|
$latest_affected_revision_id = 1;
|
||||||
}
|
}
|
||||||
$previous_revision_id = (int) $entity->getLoadedRevisionId();
|
$previous_revision_id = (int) $entity->getLoadedRevisionId();
|
||||||
$latest_affected_revision_id = $this->storage->getLatestTranslationAffectedRevisionId($entity->id(), $entity->language()->getId());
|
|
||||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $latest_affected_revision */
|
/** @var \Drupal\Core\Entity\ContentEntityInterface $latest_affected_revision */
|
||||||
$latest_affected_revision = isset($latest_affected_revision_id) ?
|
$latest_affected_revision = $this->storage->loadRevision($latest_affected_revision_id);
|
||||||
$this->storage->loadRevision($latest_affected_revision_id) : $this->storage->load($entity->id());
|
|
||||||
$translation = $latest_affected_revision->hasTranslation($active_langcode) ?
|
$translation = $latest_affected_revision->hasTranslation($active_langcode) ?
|
||||||
$latest_affected_revision->getTranslation($active_langcode) : $latest_affected_revision->addTranslation($active_langcode);
|
$latest_affected_revision->getTranslation($active_langcode) : $latest_affected_revision->addTranslation($active_langcode);
|
||||||
$entity = $this->storage->createRevision($translation, $default_revision);
|
$entity = $this->storage->createRevision($translation, $default_revision);
|
||||||
|
|
|
@ -192,12 +192,12 @@ class EntityRevisionTranslationTest extends EntityKernelTestBase {
|
||||||
/**
|
/**
|
||||||
* Tests that revision translations are correctly detected.
|
* Tests that revision translations are correctly detected.
|
||||||
*
|
*
|
||||||
* @covers \Drupal\Core\Entity\ContentEntityStorageBase::isAnyRevisionTranslated
|
* @covers \Drupal\Core\Entity\ContentEntityStorageBase::isAnyStoredRevisionTranslated
|
||||||
*/
|
*/
|
||||||
public function testIsAnyRevisionTranslated() {
|
public function testIsAnyStoredRevisionTranslated() {
|
||||||
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
|
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
|
||||||
$storage = $this->entityManager->getStorage('entity_test_mul');
|
$storage = $this->entityManager->getStorage('entity_test_mul');
|
||||||
$method = new \ReflectionMethod(get_class($storage), 'isAnyRevisionTranslated');
|
$method = new \ReflectionMethod(get_class($storage), 'isAnyStoredRevisionTranslated');
|
||||||
$method->setAccessible(TRUE);
|
$method->setAccessible(TRUE);
|
||||||
|
|
||||||
// Check that a non-revisionable new entity is handled correctly.
|
// Check that a non-revisionable new entity is handled correctly.
|
||||||
|
|
Loading…
Reference in New Issue