Summary

If you clone content with Paragraphs using the 'Node clone' module
And then delete a paragraph from the original node
The paragraph is also deleted from the cloned node

Likewise, if you delete a paragraph from the cloned node
The paragraph is also deleted from the original node

This is because both the original and cloned content both reference the same paragraphs_item.

(Thanks to rocxa for finding the cause of the issue).

Symptoms

Deleting the paragraph deletes the paragraph item, but not the references to the paragraph item, so when this issue has occurred you will see the following:

We have a paragraph field called 'body_additional'.

In the database there are still entries for each paragraph item in the 'field_data_field_body_additional' table.

However there are no corresponding entries in the 'paragraph_item' table.

There are also no entries in the individual 'field_data_*' tables, for the fields that were contained within the paragraph.

This results in a display like this on the node edit form:

Paragraph lost

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JKingsnorth’s picture

Title: Data loss » Paragraph item and contained field data loss
rocxa’s picture

+1

JKingsnorth’s picture

Issue summary: View changes
FileSize
7.04 KB

We've just experienced this issue again, so I've updated the issue summary with some more information.

JKingsnorth’s picture

Status: Active » Closed (duplicate)

Right, so this is actually a duplicate of this: #2280181: Paragraph module does not work well with Node clone module

JKingsnorth’s picture

Title: Paragraph item and contained field data loss » Paragraphs data loss with Node Clone module
Category: Support request » Bug report
Priority: Normal » Critical
Issue summary: View changes
Status: Closed (duplicate) » Active

Reactivating as the other issue addresses a sightly different problem.

Can we get this incompatibility listed on the module page at least, even if it cannot be 'fixed' here in paragraph. It has caused data loss on our site, and could do on others.

I've posted the issue to the Node Clone module here too: #2425931: Support Paragraphs module asking if Paragraphs can be listed as an exception on the module page or eventually support this module.

jeroen.b’s picture

Added a known issues section to the project page

hefox’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
Category: Bug report » Feature request
Priority: Critical » Major

Paragraphs works similar to field collections, if anyone has got the later, which is more popular tmk, working with clone, might be able to reuse that code.

Modules don't have to be compatible with each other, so as long it's not an actual bug in the module, asking the modules to work together is a feature request generally.

hefox’s picture

hefox’s picture

Here's a patch to provide integration between node_clone and paragraphs.

However, I don't see how this issue isn't a duplicate of #2280181: Paragraph module does not work well with Node clone module, which was won't fixed.

For amount of code (e.g. not a lot), maintaining a separate module to integrate with node_clone seems a bit annoying, but if paragraphs maintainers prefers that approach, that's one way to do this.

hefox’s picture

Status: Active » Needs review
JKingsnorth’s picture

Status: Needs review » Needs work

Agreed that this isn't a duplicate of the other one, sorry, I corrected myself there.

This would be a great fix to put in to the Paragraphs module. Thanks for your work on it hefox.

I haven't tested the patch yet, but I noticed this:

+++ b/paragraphs.node_clone.inc
@@ -0,0 +1,74 @@
+          paragraphs_clone_items('field_collection_item', $new_item, $new_field_name, $language);

Reference to 'field_collection_item'.

jeroen.b’s picture

Thanks, I did not realize node_clone had easy hooks!
Committed to dev with some changes (some field collection to paragraphs).

  • jeroen.b committed 4f2eb93 on 7.x-1.x
    Issue #2394313 by jeroen.b: Paragraphs data loss with Node Clone module
    
  • jeroen.b committed 5bc81f4 on 7.x-1.x authored by hefox
    Issue #2394313 by John.K, hefox: Paragraphs data loss with Node Clone...
jeroen.b’s picture

Status: Needs work » Fixed

Status: Fixed » Needs work

The last submitted patch, 9: 2394313-paragraphs-node_clone-9.patch, failed testing.

jeroen.b’s picture

Status: Needs work » Fixed

Testbot, you are creezy

JKingsnorth’s picture

Cool, thanks Jeroen

JKingsnorth’s picture

Status: Fixed » Needs review
FileSize
974 bytes

Just noticed a few typos in the comments, a couple to do with the backwards naming of node_clone's 'clone_node' hook. Just offering this patch as a perfectionist.

jeroen.b’s picture

Status: Needs review » Fixed

Thanks John, committed to dev!

  • jeroen.b committed 6b7fb11 on 7.x-1.x authored by John.K
    Issue #2394313 by John.K: Paragraphs data loss with Node Clone module
    

Status: Fixed » Closed (fixed)

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

rcross’s picture

Just a note that that this is still listed on the project page as a known problem. IF this has been truely fixed, it would be best to remove it from the project page (or update to be clearer about what the limitation is)

yoruvo’s picture

Status: Closed (fixed) » Needs work
FileSize
1.62 KB

Hello,

I have found that the hook paragraphs_form_node_form_alter in paragraphs.node_clone.inc actually had no effect, due to assuming that the fields' language arrays were in a different position than they really are.

I have attached a patch which fixed this and allowed the paragraph item IDs to be altered properly, thus allowing paragraphs to be cloned.

EDIT:

I based this patch on 7.x-1.0-rc4; hopefully it applies to the dev version.

mdeltito’s picture

There is another issue with data loss when dealing with multiple levels of nested paragraphs. This issue is also noted in #2210597: Field Collection in Field Collection in Field Collection on the field_collection_clone_node module, which appears to be the basis for this functionality in Paragraphs.

When cloning content that has a "tree" of paragraphs attached, there are cases where the entity_metadata_wrapper incorrectly returns no items for the field. This results in the loss of paragraphs items that are > 2 levels deep in the hierarchy. I have not traced out the reason why the wrapper fails, but getting rid of the wrapper and accessing the field directly is low-impact and solves this issue. Patch supplied against dev.

cslevy’s picture

#24 is working for me, but I'm getting some warnings.

Warning: array_map(): Argument #2 should be an array in paragraphs_clone_items() (line 55 of .. paragraphs/paragraphs.node_clone.inc).
Warning: Invalid argument supplied for foreach() in paragraphs_clone_items() (line 59 of .. paragraphs/paragraphs.node_clone.inc).

I updated the #24 patch to fix that as well

cslevy’s picture

Status: Needs work » Needs review
recrit’s picture

The cloning functions have serious issues with language handling - Node language != field language key.
The attached patch cleans it up with the distinction between entity language and field language.

recrit’s picture

Updated #27 to pass field language as the nested paragraphs entity language.

recrit’s picture

Note: The node clone hooks could be deprecated in favor of handling clone similar to the field_collections module. See patch on #2331273: i18n - Duplicate Paragraph Items that adds a paragraphs_field_insert() that detects cloning from any module.

mxh’s picture

People might assume from the project description that this is fixed in 8.x, but it's not. Please distinct the problem on the project page description between 7.x and 8.x. This problem may be solved for 7.x, but it's not solved for Node Clone in 8.x.

loopduplicate’s picture

#28 seems to fix the data loss problem for a project I'm working on as well. My situation:

Node -> Paragraph -> Paragraph -> Media

Without the patch, the Media field was not working. With the patch, it does.

Probably unrelated, but I'm also using the patch from https://www.drupal.org/project/paragraphs/issues/2564327#comment-12526091

loopduplicate’s picture

#28 did not solve the data loss problem as I originally thought. Here's an updated patch which does. I've reset the field_language static, copying from code added to the replicate_paragraphs module to fix nesting.

oadaeh’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed the patch in #32. The code looks good, and it works as advertised.

das-peter’s picture

Ran just into this too. Patch from #32 solved that just fine.

jstoller’s picture

Status: Reviewed & tested by the community » Fixed

Patch committed to dev.

  • jstoller committed bec9676 on 7.x-1.x authored by loopduplicate
    Issue #2394313 by recrit, JKingsnorth, loopduplicate, hefox, cslevy, ivi...

Status: Fixed » Closed (fixed)

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