'name' => 'original',
'language' => 'en',
]);
$translation =
$entity->
addTranslation('de'
);
$entity->
save();
// Clone the entity.
$clone =
clone $entity;
// Retrieve the entity properties.
$reflection =
new \
ReflectionClass($entity);
$properties =
$reflection->
getProperties(~\ReflectionProperty::IS_STATIC
);
$translation_unique_properties =
['activeLangcode', 'translationInitialize', 'fieldDefinitions', 'languages', 'langcodeKey', 'defaultLangcode', 'defaultLangcodeKey', 'revisionTranslationAffectedKey', 'validated', 'validationRequired', 'entityTypeId', 'typedData', 'cacheContexts', 'cacheTags', 'cacheMaxAge', '_serviceIds', '_entityStorages'
];
foreach ($properties as $property) { // Modify each entity property on the clone and assert that the change is
// not propagated to the original entity.
$property->
setValue($entity, 'default-value'
);
$property->
setValue($translation, 'default-value'
);
$property->
setValue($clone, 'test-entity-cloning'
);
// Static properties remain the same across all instances of the class.
if ($property->
isStatic()) { $this->
assertEquals('test-entity-cloning',
$property->
getValue($entity),
(string) new FormattableMarkup('Entity property %property_name is not cloned properly.',
['%property_name' =>
$property->
getName()]));