In inline_entity_form_field_widget_form() the $wrapper ID is based on the $instance['id']. This means that if 2 of the same field instance are placed onto the page, as they are in Commerce Registration during checkout, then the DOM has 2 elements with the same ID.
This causes IEF to load the inline form in the wrong place.
This issue is related:
#1740074: Fix IEF to work when IEF is nested into another IEF
Although that issue is related to a more specific goal of fixing nested IEF's.
Comments
Comment #1
tmsimont commentedpatch attach
Comment #2
bojanz commentedLet's continue in the other issue, since the issue is the same.
See my comment in http://drupal.org/node/1740074#comment-6710196 on how it should be done, I already said I don't want / like the "creating id from parents" approach (since the IEF id shows up in html classes, so it's just ugly.).
Comment #3
tmsimont commentedI am marking active again just to make a case about how this issue is in fact different than #1740074: Fix IEF to work when IEF is nested into another IEF
If you still disagree, just close it again.
The other issue is trying to address this issue, and 2 others in one place:
inline_entity_form_save_row_weightsso the correct order is never savedinline_entity_form_process_entity_formis not executed on nested IEFs so subentities are not savedPatching the module to fix #1740074: Fix IEF to work when IEF is nested into another IEF will be fairly time consuming whereas this issue is a simpler one, and can be addressed neatly and nicely here first. Then #1740074: Fix IEF to work when IEF is nested into another IEF can adapt to our solution here and move forward addressing those issues.
This issue also relates more closely to Commerce Registration.
I understand how it could be "ugly" but this is how the element "name" values are already calculated in drupal. I got this concept directly from core's theme_form_element()
I suppose you could use something like php's uniqid(), but I would argue that a long string containing the parents of a form element is less "ugly" than a random string of numbers and characters.
There won't really be any need to "use it across the code" -- I know the module currently generates the ID from the
$instanceparam in 2 places, but if you review my initial patch, the second generation (@@ -1093,7 +1093,7, at the end of the initial patch) can actually be replaced by a retreival of the ID from the$form, rather than a new generation.Comment #4
tmsimont commentedAttached is a patch that uses a incrementing static variable to generate a fresh ID for each IEF instance. This should fix this issue, but won't address the other problems in #1740074: Fix IEF to work when IEF is nested into another IEF
Comment #5
tmsimont commentedComment #6
jherencia commentedThere is a trailing space here.
Comment #7
tmsimont commentedbetter?
Comment #8
tmsimont commentedComment #9
jherencia commentedYep :), I think this is an start to make both issues work but let's see what @bojanz thinks.
Comment #10
jherencia commentedI am thinking that for the wrapper and the #name properties it would be better to do str_replace('_', '-', $ief_id).
What do you think?
Comment #11
tmsimont commentedI'm not sure I understand how there would be a need for that (#10). If $ief_id is already generated cleanly in 1 place (with the patch in #7), why would you need to introduce
str_replace('_', '-', $ief_id)?Comment #12
tmsimont commentedif it's the dashes vs. underscores you're after -- i could just modify this line in the patch:
+ $ief_domid = 'ief_element_' . $ief_domid;to be
+ $ief_domid = 'ief-element-' . $ief_domid;Comment #13
jherencia commentedNo, I'm saying that $ief_id is used to generate the ID of the wrapper div. The ID is using dashes and the $ief_id underscores. For the #name attributes happens the same, so it could be better to adapt the ID to conform those attributes.
Comment #14
tmsimont commentedSo do you think the suggestion in #12 would work?
Comment #15
jherencia commentedWe cannot use just one, there are cases in which the $ief_id should be used with underscores:
Code from the module
It's a Drupal standard to use undercore names for array keys.
I know this is probably the less important part of the patch but I think it is still important to keep the those standards.
Comment #16
tmsimont commentedI get it now, and agree. I'll send an updated patch today
Comment #17
tmsimont commentedOK attached is a patch for 7.x-1.x-dev that will do what the above patch did, then make all the "wrapper" elements point to a dash-separated name and let the form name parts use underscores.
I also fixed a comment:
It said "Map ID" because I copied and modified code from the getlocations module, which uses this to generate unique map id's
Comment #18
tmsimont commentedforgot to attach
Comment #19
bojanz commentedThe IEF id part is easy, the hard part is in inline_entity_form_field_attach_submit() -> processing the correct IEF from form state..
I can't just iterate over $form_state['inline_entity_form'] because that hook runs for inline forms as well, and I currently have no way to distinguish the two.
Nested IEFs make the problem even harder.
So this is not an easy thing to fix and will need to wait for another release.
Comment #20
tmsimont commentedDoesn't this part of the patch take care of that?
Comment #21
msmithcti commented@tmsimont thanks for this patch. The patch from #18 also works for multivalue field collections with inline entity forms within them.
Comment #22
tmsimont commentedno problem splatio.
@bojanz -- can you check out my comment in #20? I think we could mark this as RTBC with splatio's help.
Comment #23
fearlsgroove commentedHere's a rerolled patch that should still apply. This also seems to make nested entities work just fine in some light initial testing.
Comment #24
joe bartlett commentedThe patch in #23 fixes the issue when applied to version 7.x-1.1 and adding the widget to a field collection (version7.x-1.0-beta5).
Comment #25
CSoft commented#24
+1! Thanks, guys!
Comment #26
dwwI was pointed here via #1740074: Fix IEF to work when IEF is nested into another IEF. I haven't read the patch, but I just applied it and can definitively say it does *not* fix nested IEF in my case. :/
I've got a "Review" node type that has an entity reference called "Review by" that points to an "Author" node type, and an entity reference called "Reviewed" which points to a "Book" node type. In turn, Books have a "By" entity reference that also points to "Author". I've got all of the above ER fields configured to use IEF multiple values widgets.
When I'm creating a review node, I can use IEF to create or reference authors for the "Review by" field no problem.
I can also create or reference book nodes.
However, if I use IEF to create a new Author for the newly created book, my review node ends up with duplicate book nodes (although not with identical fields).
This is the same behavior with and without this patch. I'm using version 7.x-1.2.
If I have a chance to do a more thorough investigation I'll report back here, but either this patch isn't actually the solution to the deeper problem of nested IEF, or this patch is actually not solving the problem it wants to solve. ;)
Sorry I can't be more helpful right now...
Cheers,
-Derek
Comment #27
bendiy commentedMarked #2046953: $ief_id isn't unique enough, thus doesn't work with field collection as a duplicate of this issue.
If #26 is the case then this needs more work.
Comment #28
amitaibuEventhough #2046953: $ief_id isn't unique enough, thus doesn't work with field collection was marked as the duplicate, I think the patch provided there is better.
Comment #29
bendiy commentedAttached is a rerolled patch of #23
Comment #30
bendiy commented#2032649: Rework inline form submission solves this issue. Marking this as a dupe.
Comment #30.0
bendiy commentedfound related issue