Commit 27700fa1 authored by effulgentsia's avatar effulgentsia
Browse files

Issue #2939795 by plach, Wim Leers: Multilingual logic is not applied when a...

Issue #2939795 by plach, Wim Leers: Multilingual logic is not applied when a new revision translation is being added
parent c9392bb3
......@@ -152,6 +152,23 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values
/**
* 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
* the default revision may appear as not translated. This determines whether
* the entity has any translation in the storage and thus should be considered
......@@ -165,8 +182,9 @@ protected function initFieldValues(ContentEntityInterface $entity, array $values
* otherwise.
*
* @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 */
if ($entity->isNew()) {
return FALSE;
......
......@@ -359,12 +359,20 @@ protected function doEditStep($active_langcode, $default_revision, $untranslatab
$previous_label = NULL;
if (!$entity->isNewTranslation()) {
$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();
$latest_affected_revision_id = $this->storage->getLatestTranslationAffectedRevisionId($entity->id(), $entity->language()->getId());
/** @var \Drupal\Core\Entity\ContentEntityInterface $latest_affected_revision */
$latest_affected_revision = isset($latest_affected_revision_id) ?
$this->storage->loadRevision($latest_affected_revision_id) : $this->storage->load($entity->id());
$latest_affected_revision = $this->storage->loadRevision($latest_affected_revision_id);
$translation = $latest_affected_revision->hasTranslation($active_langcode) ?
$latest_affected_revision->getTranslation($active_langcode) : $latest_affected_revision->addTranslation($active_langcode);
$entity = $this->storage->createRevision($translation, $default_revision);
......
......@@ -192,12 +192,12 @@ public function testSetNewRevision() {
/**
* 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 */
$storage = $this->entityManager->getStorage('entity_test_mul');
$method = new \ReflectionMethod(get_class($storage), 'isAnyRevisionTranslated');
$method = new \ReflectionMethod(get_class($storage), 'isAnyStoredRevisionTranslated');
$method->setAccessible(TRUE);
// Check that a non-revisionable new entity is handled correctly.
......
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