Issue #2772979 by hchonov: Enforcing a cloned entity translation to be new propagates to the original entity
parent
e31ca782a7
commit
d2ab9b8433
|
@ -1032,6 +1032,11 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
|
|||
$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 @@ class ContentEntityCloneTest extends EntityKernelTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue