Problem/Motivation
Within the field widget, edit links on a selected entity of the same bundle as the parent entity fail to open the modal.
Steps to recreate:
1) Install standard profile,
2) install entity_browser_example
3) Create two nodes, "Node 1" and "Node 2"
4) Edit "Node 1"
5) On the "Nodes" field, select "Node 2" with the entity browser.
6) After the entity browser is closed you should see "Node 2" with an "edit" link (button).
7) Clicking on the edit button fails to open modal, and if you look at the network tab when you click, you'll see an extra command to close the modal.
Remaining tasks
Find bugFix itTest coverage- Review
- Commit
User interface changes
- none
API changes
- none
Data model changes
- none
Original issue summary
Dear All,
I have a use case with the following versions:
Drupal : 8.6.10
Entity Browser: 8.x-1.5
Test Case
1) create a Content types of type A and type B, create entity reference revision field in both A and B types and allow both A and B type of node in reference, create entity browser with all steps.
2) create node Article1 of type A and refer to both types of nodes , when trying to edit node Article1 and edit the node of type B the popup with edit for occurs but when trying to edit node of type A .. the popup does not occur.
where as if try to edit the same node in node of content type B the node edit popup opens for node of type A but not for of type B
Debugging till now:
1) when trying to edit node type A after the correct ajax call a redirection to the currently opened node edit form of type A takes place.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | entity-browser-edit-modal-bug-3036406-33.patch | 8.21 KB | oknate |
| #33 | 3036406-interdiff--22-33.txt | 8.96 KB | oknate |
Comments
Comment #2
shubhangi1995Comment #3
oknateSo launching edit form of nodes of the same type doesn't work?
Comment #4
shubhangi1995yes
Comment #5
oknateThanks for reporting. I can confirm the bug. Very odd.
I created "content type A" and "content type B", created an entity browser view that references both types, and added entity reference fields to each type that references both types, and set up an entity browser field widget for each.
I then created node 1 of type A, node 2 of type B and node 3 of type A.
Editing node 1 (of type A), after selecting node 2 and node 3, the edit button for node 2 would work, but not node 3. Node 3 is of the same type of node 1. Changing the order didn't change the bug. If Node 2 had delta 0 or delta 1, it was the same. Only the node of a different type worked.
The item of the same type would cause two ajax commands and would fail.
one posts to
http://nasdaq.mcdev/entity_browser/node/3/edit?details_id=edit-field-typ...
and one posts to
http://nasdaq.mcdev/node/1/edit?ajax_form=1&_wrapper_format=drupal_ajax
The button that works posts to
http://nasdaq.mcdev/entity_browser/node/2/edit?details_id=edit-field-typ...
So it looks like the extra post back the original form is the issue.
Adding "#executes_submit_callback" => FALSE, to the edit button is a partial fix, it allows the first button to work. But if you open the second edit form, submit it, then open the first edit form and submit it, it doesn't close and doesn't update the details wrapper for the field widget.
Comment #6
oknateComment #7
oknateYou don't even need two types.
You can install standard profile, enable entity browser example and add two entity_browser_test nodes, node 1 and node 2. Go back and edit node 1 and on the nodes field select node 2. The edit button doesn't work.
Comment #8
shubhangi1995yes i tested it now, you are correct, i mentioned the steps above as that was my test case..
Could you please guide me how i could move towards solving this bug.. because as far as i could debug it had conflict with drupal.js
Comment #9
oknateHere's a fix. The posted form data was conflicting, since Drupal saw that it was the same form id, and there was posted data it was trying to populate the form in the modal with data from the parent. The fix is simple, if the triggering button is the edit button, remove the post data. It did require giving an explicit name to the edit button. That may break some functional tests.
Comment #11
primsi commentedComment #12
gido commentedI can reproduce the issue and it look like patch #9 address it (for me).
This is radical to reset all the POST data. Do you see a way to be a bit more "chirugical" here ?
Comment #13
oknateGiven that POST is normally empty when you reach an entity edit form, I'm not sure how much value saving anything would be, and it would add a lot of code for no apparent reason.
If you visit /node/1/edit, you'll see an empty ParameterBag at \Drupal::requestStack()->getCurrentRequest()->request.
Comment #14
oknateComment #15
oknateFixing an issue I noticed where closing the modal without submitting it and reopening it would cause two modals to open. I'm not really sure why adding this code fixed it, but instead of just emptying out the request, I'm setting it to a variable, building the form and then setting it back. Something in the request is used during the build to assure the modal's close button behaves appropriately.
Comment #17
oknatefailing test in #15 was due to #3040286: PluginsTest failing on 8.6.11 (now fixed)
Comment #18
oknateHere's a patch which demonstrates the bug. It doesn't have the fix in it, only the test coverage, the next patch posted includes the fix. Also note, I included the update to the test class in #3040770: Update test classes extending EntityBrowserJavascriptTestBase, so that it uses web driver.
Comment #19
oknateHere's an updated patch with the fix and the test coverage.
Comment #22
oknateMinor coding standard fix.
Comment #23
oknateComment #24
oknateComment #25
oknateComment #26
oknateComment #27
oknateComment #28
oknateComment #29
oknateComment #30
oknateComment #31
shubhangi1995confirmed my issue got resolved :) i could work with it now
thanks
Comment #32
shubhangi1995Comment #33
oknateReroll
Comment #36
oknateCommitted