Problem/Motivation
This issue is similar to #2772979: Enforcing a cloned entity translation to be new propagates to the original entity and #2828073: Cloning an entity with initialized translations leaves $entityKeys and $translatableEntityKeys pointing to the old entity object and the problem has been initially mentioned in #2828073: Cloning an entity with initialized translations leaves $entityKeys and $translatableEntityKeys pointing to the old entity object, but in order to keep each problem separately there is an isolated issue for the $values entity property.
What happens is that if an entity with at least one translation initialized is cloned then the $values property will be shared between the clone and the original entity and under circumstances the values of both entity will get mixed up. An example use is:
- Create an entity with at least one translation.
- Clone the entity or its translation.
- Alter a field value on the cloned entity object.
- Serialize the entity and the clone.
- Read out the value of the field that has been changed from the original entity.
- The returned value now is not the one from the original entity, but the altered one from the cloned entity object.
Proposed resolution
Break the reference of the property $values in CEB::__clone().