To reproduce:

- edit a node that has a multi-valued reference field, with multiple values set
- open two or more entities to edit.
- click 'cancel' on one of the inline forms
- result: all the forms close. Expected result: only the one where I click 'cancel' should close

Comments

joachim created an issue. See original summary.

lowfidelity’s picture

Instead of passing the topmost parent IEF element to inline_entity_form_close_all_forms(...) in the button #submit callback closeChildForms(..) we only pass the IEF element that holds the clicked close button.

This only closes the IEF element holding the 'Cancel' button and all it's nested IEF elements, instead of closing all IEF elements inside the widget.

lowfidelity’s picture

Status: Active » Needs review
geek-merlin’s picture

Thanks a lot! Code looks good. Tests are green.

+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
@@ -1000,8 +1000,18 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
+    $array_parents = array_slice($triggering_element['#array_parents'], 0, -2);

I'd appreciate a comment on that line, what keys are sliced away. Makes the code more maintainable.

If someone else does a manual test and sets RTBC, we can commit this.

lowfidelity’s picture

I added the comments.

geek-merlin’s picture

OK, looks good! I missed that the new code does not have automated tests. Can you look into the existing tests and extend them to cover the new code?

lowfidelity’s picture

I'll try to write those tests, but I have absolutely no experience with test driven development. I browsed through the docs and I think I understand the technical part of it. Though, I find it hard to decide what kind of tests are required in this particular case.

Also, can I simply add my code to existing tests if they are suitable or does every patch require it's tests in a separate file?

Could you please point me into the right direction? Any nice tutorials that explain the theoretical part of writing tests for Drupal?

Thanks a lot!

geek-merlin’s picture

THH, i'm not experienced at writing tests though, and i distract from this fact by nudging others to do so as maintainer. ;-) But hey, this is really important to have a complex (and ermm, partly convoluted) module like this maintainable.

As of pointers, look into the official docs and i think most important is to understand the types of tests: https://www.drupal.org/docs/8/testing/types-of-tests-in-drupal-8

> Also, can I simply add my code to existing tests if they are suitable or does every patch require it's tests in a separate file?

I think it is not only OK but a good thing to extend an existing test in a way that covers what you fix by this patch.
And do not cheap out on comments! They help others (including your future self ;-).

What you essentally do is

* In the issue summary, write a how-to-reproduce such that any moron will understand exactly what to click
* Write that in code

Ne next thing you do is

* upload a "test-without-fix" patch (which *must* turn out red and proves that your test tests what need be tested)
* in the same comment, upload the "test-plus-fix" patch (which then proves that the fix is a fix)

HTH!

joachim’s picture

I can confirm the patch fixes the problem.

The tests are quite complex and most of them seem to be set up with multi-level nesting, so it's not going to be simple to figure out where and how to add the test for this!

lowfidelity’s picture

Yeh. I've been using the patch in production for half a year, so I'm pretty sure it works as it should.

I also added all sorts of functionality, like selecting multiple referenced entitties and updating their fields, etc. I wrote up a little blog post about that here https://www.lowfidelity.at/blog/quick-edit-drupal-inline-entity-form

Also here's a related patch that allows "quick editing" related entities: https://www.drupal.org/project/inline_entity_form/issues/3127011

Still, I didn't find the time to get into writing tests. If anyone could help me get a quick start on that topic, I'd like to volunteer some time to get those patches into the module.

geek-merlin’s picture

Title: clicking 'cancel' when several entities in the same field have their form open closes all the inline forms » D8: Multiple forms submit/cancel closes all child forms
Related issues: +#2343689: D7: Multiple forms submit/cancel closes all child forms

Found an olde issue which may or may not help.

socialnicheguru’s picture

Status: Needs review » Needs work

No longer applies to inline_entity_form 1.0.0-rc12

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

Rerolled patch #5 for 8.x-1.x branch, please review it.

podarok’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs review » Needs work
git apply inline_entity_form-close-only-forms-where-close-clicked-3061620-13.patch 
error: patch failed: src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php:1021
error: src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php: patch does not apply

needs reroll

lowfidelity’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB

Rerolled patch #5 for 2.0.x-dev branch and fixed some coding standard issues.

lowfidelity’s picture

Patch applies successfully to 2.0.x-dev and 2.0@beta.

Automated tests for patch #15 fail with PHP 8.1 & MySQL 8, D9.5 run-tests.sh fatal error due to an unrelated error:

PHP Fatal error: Uncaught Error: Class "Drupal\inline_entity_form\Tests\InlineEntityFormTestBase" not found in /var/www/html/modules/contrib/inline_entity_form/src/Tests/ContentModerationTranslationTest.php:12

See issue #2989028: https://www.drupal.org/project/inline_entity_form/issues/2989028#comment...

  • podarok committed 2a409b43 on 2.0.x authored by paper boy
    Issue #3061620 by paper boy, mrinalini9: D8: Multiple forms submit/...
podarok’s picture

Status: Needs review » Fixed

#16 is in
tnx

Status: Fixed » Closed (fixed)

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

geek-merlin’s picture

Version: 2.0.x-dev » 3.x-dev
Status: Closed (fixed) » Needs work
Related issues: +#3401656: Clean up problematic 2.x branch

Bulk reopen. Tag says needs tests.