Skip to content
Snippets Groups Projects

Avoid creating a clone per language

Open Luca Lusso requested to merge issue/entity_clone-3426414:3426414-too-many-clone into 2.x
1 file
+ 8
7
Compare changes
  • Side-by-side
  • Inline
@@ -128,13 +128,14 @@ class ContentEntityCloneBase implements EntityHandlerInterface, EntityCloneInter
if ($cloned_entity instanceof FieldableEntityInterface && $entity instanceof FieldableEntityInterface) {
foreach ($cloned_entity->getFieldDefinitions() as $field_id => $field_definition) {
if ($cloning_method = $this->getCloneCallback($field_definition)) {
foreach ($languages as $language) {
$cloned_translation = $cloned_entity->getTranslation($language->getId());
$entity_translation = $entity->getTranslation($language->getId());
$field = $entity_translation->get($field_id);
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $value */
if ($field->count() > 0) {
$cloned_translation->set($field_id, $this->$cloning_method($field, $field_definition, $properties, $already_cloned));
$field = $entity->get($field_id);
if ($field->count() > 0) {
$cloned_references = $this->$cloning_method($field, $field_definition, $properties, $already_cloned);
foreach ($languages as $language) {
$cloned_translation = $cloned_entity->getTranslation($language->getId());
$cloned_translation->set($field_id, $cloned_references);
}
}
}
Loading