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 bug
  • Fix it
  • Test 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.

Comments

shubhangi1995 created an issue. See original summary.

shubhangi1995’s picture

Issue summary: View changes
oknate’s picture

So launching edit form of nodes of the same type doesn't work?

shubhangi1995’s picture

yes

oknate’s picture

Thanks 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.

oknate’s picture

Title: Redirection to same edit page » Edit button of same type doesn't work.
Priority: Critical » Major
oknate’s picture

You 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.

shubhangi1995’s picture

yes 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

oknate’s picture

Status: Active » Needs review
StatusFileSize
new2.45 KB

Here'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.

Status: Needs review » Needs work
primsi’s picture

Issue tags: +drupalmountaincamp
gido’s picture

I can reproduce the issue and it look like patch #9 address it (for me).

+    if ($edit_button) {
+      // Remove posted values from original form to prevent
+      // data leakage into this form when the form is of the same bundle.
+      $request->request = new ParameterBag();
+    }

This is radical to reset all the POST data. Do you see a way to be a bit more "chirugical" here ?

oknate’s picture

Given 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.

oknate’s picture

Version: 8.x-1.5 » 8.x-2.1
oknate’s picture

Status: Needs work » Needs review
StatusFileSize
new3.16 KB
new60.9 KB

Fixing 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.

Status: Needs review » Needs work
oknate’s picture

Status: Needs work » Needs review

failing test in #15 was due to #3040286: PluginsTest failing on 8.6.11 (now fixed)

oknate’s picture

Here'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.

+    $assert_session->buttonExists('edit-field-entity-reference1-current-items-0-edit-button')->press();
+
+    // test edit dialog by changing title of referenced entity.
+    $edit_dialog = $this->assertSession()->waitForElement('xpath', '//div[contains(@id, "node-' . $target_node->id() . '-edit-dialog")]');
+    $title_field = $edit_dialog->findField('title[0][value]');
+    $title = $title_field->getValue();
+    $this->assertEquals('Walrus', $title);
+    $title_field->setValue('Alpaca');
+    $this->assertSession()->elementExists('css', '.ui-dialog-buttonset.form-actions .form-submit')->press();
+    $this->assertSession()->assertWaitOnAjaxRequest();
+    // Check that new title is displayed.
+    $this->assertSession()->pageTextNotContains('Walrus');
+    $this->assertSession()->pageTextContains('Alpaca');
oknate’s picture

Here's an updated patch with the fix and the test coverage.

The last submitted patch, 18: entity-browser-edit-modal-bug-3036406-test-only--should-fail.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 19: entity-browser-edit-modal-bug-3036406-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

oknate’s picture

Status: Needs work » Needs review
StatusFileSize
new973 bytes
new15.13 KB

Minor coding standard fix.

oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
shubhangi1995’s picture

confirmed my issue got resolved :) i could work with it now
thanks

shubhangi1995’s picture

Status: Needs review » Reviewed & tested by the community
oknate’s picture

  • oknate committed 6b3dfbd on 8.x-2.x
    Issue #3036406 by oknate: Edit button of same type doesn't work
    

  • oknate committed 4e43d37 on 8.x-1.x
    Issue #3036406 by oknate: Edit button of same type doesn't work
    
oknate’s picture

Status: Reviewed & tested by the community » Fixed

Committed

Status: Fixed » Closed (fixed)

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