I was trying to replicate a node which had a paragraphs field that could be translated. Every time I replicated the node, the copy node would have the paragraphs items but in ['und'] rather than the original language(s) that were set.

I looked into the code and found that we are not passing the language into setHostEntity(). After I passed the language in it was able to save the new copy of the paragraphs items to their correct language(s) on the field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joekers created an issue. See original summary.

joekers’s picture

Status: Active » Needs review
FileSize
636 bytes

Patch attached.

rossb89’s picture

Status: Needs review » Reviewed & tested by the community

Brilliant, just ran into this issue and was about to go looking for where to patch.

Thanks!

  • seanB committed ce37d24 on 7.x-1.x authored by joekers
    Issue #2653604 by joekers: Replicate paragraphs doesn't work with entity...
seanB’s picture

Status: Reviewed & tested by the community » Fixed

Thnx!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mozh92’s picture

Patch doesn't work after default language.
We have 8 languages and clone work only for 'de' and 'en'.
First language in $entity->$field_name we have 'de' and it works, after that we have default language 'en' and also works, but after we get next language and we have $old_items empty.

foreach ($entity->$field_name as $language => $values) {
    replicate_paragraphs_clone_items($entity, $entity_type, $field_name, $language);
  }
$entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
$old_items = $entity_wrapper->{$field_name}->value();

Fix for this problem:

$old_items = $entity_wrapper->language($language)->{$field_name}->value();