There is an issue where new nested paragraphs are being deleted during workbench_moderation_store. The case is the following:
1- Create a bundle paragraph with some fields.
2- Create a second bundle with a paragraph field that accepts the first bundle with multiple values.
3- Create a content type and put a paragraph field that accepts the second bundle.
4- Create a node with only one item inside the field and publish it using workbench moderation.
5- Create a draft of that published node and add another item on the paragraph field.
When saving, during live version save, paragrahps_field_update is called for each paragraph item. When it's called for the items of the first bundle, parent entity is not a node, so it has not the "updating_live_revision" flag and then does all the update. In the end it gets deleted and even worse, the reference on the field is not deleted.
Posible solution
Looking at the code, I've found an apparently easy solution: Use the "updating_live_revision" flag on paragraphs_field_presave instead of paragraphs_field_update. My reasoning is that presave is being fired for all the items inside the parent paragraph item, so it gets to paragraphs_field_update and because parent paragraph doesn't have this flag, items not in live version are kept on $original_by_id variable and deleted without deleteing the parentEntity reference.
I don't know if paragraphs_field_presave is necessary on the "updating_live_revision" process, but I bet that those paragraphs fields shouldn't be updated for the live version of the node. So far, my testing has been positive. Incoming patch in next comment.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | paragraphs_workbench_moderation-2603424-35.patch | 2.7 KB | jstoller |
Comments
Comment #2
pryrios commentedComment #3
recrit commentedComment #4
recrit commentedThis patched worked for me. Live and current draft of the node now save correctly.
The paragraphs module is similar to the field collections module, and it implements the same code in field_collection_field_update().
Comment #5
jstollerI remember working on that Field Collection patch a couple years ago. For reference, that issue was #1807460: Field collection doesn't play nice with workbench moderation (patch).
Comment #6
farse commentedThis patch has come not a moment too soon, worked for me too!
Comment #7
jstollerComment #8
rp7 commentedPatch in #2 works. Thanks!
Comment #9
jstollerPosting a related issue that also effects Workbench Moderation users and could use some help: #2609754: Deleting forward revision confuses Paragraphs. In the mean time, be careful when deleting draft revisions!
NOTE: This other issue should have no impact on the patch available here, which is already RTBC. It just has a similar audience.
Comment #10
markconroy commentedHi Guys,
I have been working on a rather large (multilingual) website and this issue appeared. Actually took a while to track down that the issue was paragraphs nested inside paragraphs in draft state in workbench moderation-enabled nodes.
I applied the patch from #2 above, and all seems to be working fine so far. Thanks a lot.
Comment #11
Yaron Tal commentedAs also mentioned in #2243595: Nested field collections don't play nice with workbench moderation (revisions), both paragraphs and field_collections have some trouble with workbench_moderation when nested. Attached patch will keep checking for host entities until no higher level is possible before checking for the workbench_moderation flag.
Comment #12
Yaron Tal commentedComment #13
jbaum_13 commentedPatch #2 works to resolve issue with paragraph content added by editors being deleted when a draft is saved. I am however experiencing an issue with the published paragraph bundle content being hidden to unauthenticated users when there is a draft version of the page saved.
Comment #14
gadaniels72 commentedTested patch #11 and it does solve the problem with paragraphs being lost when workbench moderation is used. Followed the steps in the issue summary and verified:
Ran two additional scenarios to test where the paragraphs were more deeply nested and had the same successful results. One added another unlimited paragraph bundle to the nested item (so I had content type->paragraph bundle->paragraph bundle->paragraph bundle) and one that added another unlimited paragraph bundle to the origin item (so content type->paragraph bundle->2 different nested bundles)
Comment #15
jeroen.b commentedThanks @Yaron Tal, looking good.
I'm currently trying to get the quality of the code up to par with the D8 version.
That mostly just means we need to add many tests to make sure we won't break anything.
Are you able to create a unit test for this? (and provide 2 patches: 1 with the fixed code + test, 1 with the test only. that way we can see the test actually confirms it is fixed now).
Comment #16
eelkeblokI am running into a seemingly highly related issue with an image field, where a newly uploaded image (through media) is removed immediately when saving the node. Researching this I noticed that patch 11 moves the logic from hook_field_presave (as it was in patch 2) to hook_field_update. I discussed with Yaron (author of #11) and he couldn't remember the reason. Possibly because that was simply what was done in the field_collection module as well. My issue with the image is resolved when I move the logic from #11 back to _presave. I just have to do some testing to see if the original issue is solved as well (maybe write those tests...).
Comment #17
eelkeblokComment #18
eelkeblokI'm hitting a brick wall trying to get a test case going for this. Here's what I have (if you want to try, copy this into paragraphs.test).
For some reason, the last step seems to completely remove all nested paragraphs, while the expected behaviour (without the patch) is that only the newly added content is not found (adding the patch doesn't change anything either). When reproducing this manually, these steps reproduce the issue (i.e. the originally added content is preserved in the draft). Can anyone spot a problem with the above test?
Comment #19
ben.kyriakou commentedI've encountered this issue today in a separate context to where I've found it before, and in an even more broken way. When using Paragraphs in conjunction with Entity Reference and Workbench Moderation, the following will result in AJAX errors:
- Create a node type NodeType1 and NodeType2
- Create a paragraph type ParagraphType1 with an entity reference field to NodeType2. Add this to NodeType1
- Create a node of type NodeType2 and publish it
- Create a node of type NodeType1 with a paragraph field value and publish it
- Create a draft of this node and add another paragraph field
- Edit this node and try to add a reference in the second paragraph field
You'll get a 403 error on the path
entityreference/autocomplete/single/field_para_files_ref/paragraphs_item/para_file/[id]which, if you spend a lot of time digging into it, this turns out to be an access issue inparagraphs_paragraphs_item_access()because it believes the paragraph doesn't have a hostEntity. Applying the above patch somehow makes it worse, since it then believes all paragraphs loaded in this way don't have a hostEntity.Eventually I tracked this down to the loading of the host entity in
ParagraphsItemEntity->fetchHostDetails(). The checks that it does forParagraphsItemEntity::isInUse()always fall over when it thinks the item isn't using the default entity, which most cases with workbench moderation is flawed. I'm not sure of the intent of this, and the interactions with the archived flag, but changing this code to simply load in the host entity by revision every time did the trick for me. This still seems to preserve the draft attachment behaviour, with the added bonus that you can load in draft paragraphs and retrieve the correct host entity.Patch attached - still requires tests and may need some tidying, but it passes the existing tests so hopefully isn't breaking anything further.
Comment #20
ben.kyriakou commentedMoving to Needs Review for testbot.
Comment #21
chrisolofAfter running into the image field issues outlined comment #16 here and in issues #2665662: Paragraph and Workbench Moderation Image Issue and #2658244: Para image field edit not saved on node save as draft (moderation), I can confirm that both the patch in comment #2 and the patch in comment #19 solved it for me. Either one works. The patch in #11 does not fix the image issue - likely for the reasons outlined by @eelkeblok in comment #16.
Comment #22
josephdpurcell commentedSetting to critical given there is data loss.
Comment #23
jazzslider commentedI've spent some time this afternoon trying to reproduce the issue on Drupal 8 —it seems to occur there too, when I follow the OP's steps.
With that in mind, I'm wondering —is there a D8-portable fix for this as well as the D7 patch already in the queue? At the moment I'm not terribly familiar with the extent to which Paragraphs was rearchitected for D8.
Comment #24
capfive commentedI ran into this issue with a file field.
Have a node which has an embedded paragraphs field which allows for unlimited values.
First paragraph saves, second paragraph wont save unless negating workbench and going straight to published.
After applying patch #19 it now works as intended.
Based on chrisolof's test as well as my own I think we can mark this as R&T :)
Thank you for the hard work, this saved my backside for a client that was relying on both these working in unison together.
Comment #25
Yaron Tal commentedStill needs tests
Comment #26
capfive commentedOk then we should put it to needs review then?
Comment #27
eelkeblokIt needs automated tests in the patch :) So the patch needs work. See #18 for a possible starting point for a test case.
Comment #28
Sridar commented#2 worked for me. It's been one week that we are struggling to fix this. Thanks @Pryrios
Comment #29
josephdpurcell commentedAdding "Needs tests" since that's all that's left. And adding "Dublin2016" in case any sprinters would like to work on this.
Comment #30
oualid-ezr commented#2 worked for me too!
Comment #31
jstollerStill needs unit tests, re: #15.
Comment #32
solideogloria commentedObviously, no one cares to create unit tests for D7. Just include the fix. If unit tests are necessary, create a separate issue for them.
Comment #33
solideogloria commentedSomeone may need to reroll the patch
Comment #34
jstollerHere's a re-roll of the patch from #19 against the latest dev. There are no additional code changes.
Comment #35
jstollerAdding back the fix from #11 that was dropped and re-rolling against dev.
Comment #37
jstoller