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:
Comment | File | Size | Author |
---|---|---|---|
#32 | interdiff-2394313-28-32.txt | 3.07 KB | loopduplicate |
#32 | paragraphs_data_loss-2394313-32.patch | 1.87 KB | loopduplicate |
| |||
#28 | interdiff-2394313-27-28.txt | 1.41 KB | recrit |
#28 | paragraphs_data_loss-2394313-28.patch | 2.91 KB | recrit |
| |||
#27 | interdiff-2394313-25-27.txt | 2.86 KB | recrit |
Comments
Comment #1
JKingsnorth CreditAttribution: JKingsnorth commentedComment #2
rocxa CreditAttribution: rocxa commented+1
Comment #3
JKingsnorth CreditAttribution: JKingsnorth commentedWe've just experienced this issue again, so I've updated the issue summary with some more information.
Comment #4
JKingsnorth CreditAttribution: JKingsnorth commentedRight, so this is actually a duplicate of this: #2280181: Paragraph module does not work well with Node clone module
Comment #5
JKingsnorth CreditAttribution: JKingsnorth commentedReactivating 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.
Comment #6
jeroen.b CreditAttribution: jeroen.b commentedAdded a known issues section to the project page
Comment #7
hefox CreditAttribution: hefox commentedParagraphs 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.
Comment #8
hefox CreditAttribution: hefox commentedThere is a field collection node clone module: http://cgit.drupalcode.org/field_collection_node_clone/tree/field_collec...
Comment #9
hefox CreditAttribution: hefox commentedHere'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.
Comment #10
hefox CreditAttribution: hefox commentedComment #11
JKingsnorth CreditAttribution: JKingsnorth commentedAgreed 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:
Reference to 'field_collection_item'.
Comment #12
jeroen.b CreditAttribution: jeroen.b commentedThanks, I did not realize node_clone had easy hooks!
Committed to dev with some changes (some field collection to paragraphs).
Comment #14
jeroen.b CreditAttribution: jeroen.b commentedComment #16
jeroen.b CreditAttribution: jeroen.b commentedTestbot, you are creezy
Comment #17
JKingsnorth CreditAttribution: JKingsnorth commentedCool, thanks Jeroen
Comment #18
JKingsnorth CreditAttribution: JKingsnorth commentedJust 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.
Comment #19
jeroen.b CreditAttribution: jeroen.b commentedThanks John, committed to dev!
Comment #22
rcross CreditAttribution: rcross at CrossFunctional commentedJust 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)
Comment #23
yoruvo CreditAttribution: yoruvo commentedHello,
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.
Comment #24
mdeltito CreditAttribution: mdeltito at Phase2 commentedThere 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.
Comment #25
cslevy CreditAttribution: cslevy at AG Prime commented#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
Comment #26
cslevy CreditAttribution: cslevy at AG Prime commentedComment #27
recrit CreditAttribution: recrit commentedThe 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.
Comment #28
recrit CreditAttribution: recrit commentedUpdated #27 to pass field language as the nested paragraphs entity language.
Comment #29
recrit CreditAttribution: recrit commentedNote: 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.
Comment #30
mxhPeople 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.
Comment #31
loopduplicate#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
Comment #32
loopduplicate#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.
Comment #33
oadaeh CreditAttribution: oadaeh at Hook 42 commentedI reviewed the patch in #32. The code looks good, and it works as advertised.
Comment #34
das-peter CreditAttribution: das-peter at Cando commentedRan just into this too. Patch from #32 solved that just fine.
Comment #35
jstollerPatch committed to dev.