Skip to content
Snippets Groups Projects

Update src/DeepCloningTrait.php

1 file
+ 7
0
Compare changes
  • Side-by-side
  • Inline
+ 7
0
@@ -92,6 +92,11 @@ trait DeepCloningTrait {
$reflectionMethod->setAccessible(TRUE);
$entity = $reflectionMethod->invoke($plugin_block);
$duplicate_entity = $entity->createDuplicate();
// Hacky way of making sure the block is in the language of the rest of the page.
// Ideally we would get the language passed from the parent entity itself to avoid bugs with other ways of translating.
// OR at least some dependency injection here to get the current language.
$lang_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
$duplicate_entity->set('langcode', $lang_code);
$configuration['block_uuid'] = NULL;
$configuration['block_revision_id'] = NULL;
$configuration['block_serialized'] = NULL;
@@ -159,6 +164,8 @@ trait DeepCloningTrait {
}
$new_entity_reference = $entity_reference->createDuplicate();
$lang_code = \Drupal::languageManager()->getCurrentLanguage()->getId();
$new_entity_reference->set('langcode', $lang_code);
$new_entity_reference->save();
$new_referenced_target_ids[] = ['target_id' => $new_entity_reference->id()];
// Recursive call.
Loading