Skip to content
Snippets Groups Projects
Commit 33c271de authored by catch's avatar catch
Browse files

Issue #2772979 by hchonov: Enforcing a cloned entity translation to be new...

Issue #2772979 by hchonov: Enforcing a cloned entity translation to be new propagates to the original entity

(cherry picked from commit d2ab9b84)
parent 5552cb81
No related branches found
No related tags found
No related merge requests found
......@@ -1032,6 +1032,11 @@ public function __clone() {
$this->clearTranslationCache();
$translations = $this->translations;
$this->translations = &$translations;
// Ensure the enforceIsNew property is actually cloned by overwriting the
// original reference with one pointing to a copy of it.
$enforce_is_new = $this->enforceIsNew;
$this->enforceIsNew = &$enforce_is_new;
}
}
......
......@@ -62,4 +62,31 @@ public function testFieldEntityReferenceAfterClone() {
}
}
/**
* Tests that the flag for enforcing a new entity is not shared.
*/
public function testEnforceIsNewOnClonedEntityTranslation() {
// Create a test entity.
$entity = EntityTestMul::create([
'name' => $this->randomString(),
'language' => 'en',
]);
$entity->save();
$entity_translation = $entity->addTranslation('de');
$entity->save();
// The entity is not new anymore.
$this->assertFalse($entity_translation->isNew());
// The clone should not be new as well.
$clone = clone $entity_translation;
$this->assertFalse($clone->isNew());
// After enforcing the clone to be new only it should be flagged as new,
// but the original entity should not be flagged as new.
$clone->enforceIsNew();
$this->assertTrue($clone->isNew());
$this->assertFalse($entity_translation->isNew());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment