The "Single variations" widget can't be used inside IEF, and will produce a big crash in 2.12:
However this would be a very useful scenario, so we should fix it.
Steps to reproduce
- Create a content type "Event"
- Add a field "Booking details" of type Entity reference to Product and set the widget to "Inline entity form - Complex"
- Create a product type "Event booking"
- Set the widget for the "Variations" field to "Single variation (Product information)"
- Edit a node of type "Event"
- Click to edit the inline "Booking details"
- Without the patch - crash
- With the patch - fails to save when you click update; works if instead you leave the IEF open
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screenshot (307).png | 9.19 KB | tonytheferg |
| #2 | commerce.single-variation-nested.3035155-2.patch | 686 bytes | adamps |
Comments
Comment #2
adamps commentedComment #3
adamps commentedComment #4
bojanz commentedI wonder if we can find a combination of parents that works both inside and outside IEF, without checking for the form element.
Comment #5
adamps commentedYes that would be nice but I couldn't see how. However I don't have much knowledge in this area, so maybe an expert can figure it out.
Comment #6
tonytheferg commented+ 1 on the patch so far AdamPS! I am using it in 8.x-2.13, and it removed the error when creating single variation products within content using IEF. Thanks very much for the patch! Hopefully it can get RTBC and integrated!
Comment #7
tonytheferg commentedWe might want to look into what can be done for when you delete a product that was created with IEF nested in a node.
When you navigate to the node, it should refresh the IEF form. Right now it gives a message "Unable to load the referenced entity."
Comment #8
adamps commented@ToneLoc
Comment #9
tonytheferg commentedActually, #7 is only an issue when the inline entity form entity reference is set to simple under manage form display for the content that is referencing it.
Using inline entity form - complex after this patch is applied, and deleting a referenced product worked fine, with no adverse affects that I noticed
I have not tried all of the use cases, nor have I ever RTBC anything, so I would like to just leave it at a +1 and let someone more experienced RTBC.
Comment #10
tonytheferg commentedI have had this patch installed for quite some time and it has been very stable. Going to go ahead with RTBC.
Comment #11
tonytheferg commentedSeeing that this patch doesn't resolve the issue i mentioned with simple IEF, I thought it good to specify that this patch resolves complex inline entity forms, not simple. See my comment #7 about deleting product references from simple forms.
Comment #12
tonytheferg commentedChanging this to needs review as complex IEF products that have been saved in a node don't update properly, you have to save the piece of content with the IEF form open instead of clicking update.
Comment #13
tonytheferg commentedSorry for the back and forth on this. The bug i mentioned i don't think has anything to do with the patch. And it only affects a use case where the IEF is collapsed and able to be updated. Navigating to products they save fine, they just don't update the variation when the product is nested in a node. You have to leave the IEF open and save the node.
I will go back to my original story of letting someone more experienced RTBC. The patch has still been working great for me for some time now.
Comment #14
adamps commented@ToneLoc you are right, I see exactly what you describe. I believe it worked when I first created the patch, but it doesn't now. Maybe something has changed elsewhere?
Comment #15
tonytheferg commentedMy comment in #12 is a known issue with IEF. Your patch seems fine.
Comment #16
adamps commentedSo is there an open Drupal.org issue?
Results of my testing:
Comment #17
adamps commentedSingleVariationWidget displays an entity inline, so maybe the ideal fix would be for it to extend InlineEntityFormBase. If we did that then it would participate correctly in the deferred saving.
I had a quick experiment but it seems like it's not an especially easy fix for someone not expert in commerce.
Comment #18
tonytheferg commented@AdamPS,
Yes there are a few issues referencing each other on IEF behavior that doesn't allow update on a collapsed IEF. I'll see if I can track it down, but I think its unrelated to your patch, and I think your patch resolves the issue for complex online entity forms.
Comment #19
tonytheferg commentedComment #20
mglamanThis definitely needs an update on how to reproduce, so it can be tested – especially since there isn't a FunctionalJavascript test
Comment #21
adamps commentedAdded thanks. I'm not sure if "needs review" is correct because the patch doesn't fully work. However it does improve things somewhat so maybe that's OK.
Sorry I don't know how to write a FunctionalJavascript test hopefully someone else can help with that.
Comment #22
tonytheferg commentedMglaman asked me to give steps to test so he can have a look. (I reached out to him on Slack)
We might need to limit the widget to not allow simple IEF and only allow complex IEF on a single variation. Simple IEF has the behavior I mentioned above. That might be an IEF problem, but having it work with complex is better than nothing.
None of this will of course fix native IEF problems. We need to track those issues down in the que and see if any progress has been made.
Comment #23
demonde commentedThe patch works for me.
Comment #24
tonytheferg commented@demonde what version of Drupal and what version of commerce? I am currently testing this on Drupal 9 with the most recent commerce
Comment #25
tonytheferg commentedSo the patch seems to work in Drupal 9 as well.
In testing with:
Drupal 9.0.1,
Inline Entity Form 8.x-1.0-rc6
Drupal Commerce 8.x-2.20
Though the crash doesn't happen with a "single variation" variation field, and complex inline entity form entity reference on the node. The submit buttons for "Create product", and also "Update Product" are "broken". So without the patch, You can reference existing products through the IEF, but you can't create new products. You also can't Update products through the IEF. If you try edit the product in the IEF on the node, or If you try create a new product in the IEF on the node, the submit button won't work, and you will find the following error in the log:
Error: Call to a member function getEntity() on null in Drupal\commerce_product\Plugin\Field\FieldWidget\SingleVariationWidget->extractFormValues() (line 160 of C:\Users\user\Sites\devdesktop\my-project\web\modules\contrib\commerce\modules\product\src\Plugin\Field\FieldWidget\SingleVariationWidget.php)Applying the patch manually fixes both of these behaviors in my testing.
Comment #26
stephenplatz commentedI can confirm that this patch solves the issue of adding new single-variation products with the IEF; there is another issue I'm having that may be unrelated, which is I can't reference existing products with the same IEF, neither the Starts with nor the Contains options for selecting existing single-variation products produces results. The browser console doesn't show any errors on the requests, but the form isn't working for some other reason that I'll need to dig into a little more to investigate.
editThe issue with adding existing products was my own user error; the patch does solve the issue I was having adding new products.
Comment #27
tonytheferg commentedCan someone review this bug to verify?
Comment #28
mglamanLooks good to me. I'll merge after the retests pass.
Comment #29
mglamanThe D9 failures are due to a test deprecation problem.
Comment #31
mglaman🥳 Committed!
Comment #32
adamps commentedGreat many thanks.
Recap from #16:
So I have altered the issue title to describe scenario #2.
I have raised #3174532: Allow "Single variations" widget to be used inside Complex Inline Entity Forms to cover scenario #3.