I saw that the controller's entityForm() method has $entity_form[#op]. However, this is 'edit' in both cases, editing an inline entity and adding a new one.
Or is it in fact reflecting the operation on the outer form?
A way of knowing the op in the inner form is necessary I think.
Also, I assume from the way this works that there's sort of a third state: editing an entity that's now saved in the form (so not new, as in the form is populated with data) but hasn't yet been added to the database (so still sort of new, as in, don't do any database queries based on the data).
Comments
Comment #1
bojanz commentedThat falls under "edit".
A normal add (node page just loaded, add form opened), should have #op sets to "add" normally.
Comment #2
joachim commentedRight, but the inline entity being edited is in a no-mans-land, right?
This is the steps to get there:
1. Either add or edit a node, doesn't matter which
2. Go to add a new product ( ie inline entity)
3. Click the 'save product' button but don't save the main form
(optional: 4. Do something else such as edit node form element, or edit an existing product)
5. Click 'edit product' on the first product.
It's being edited... but AFAICT it's not saved in the database, but stored in the form values. So if an entity was going to assume 'edit' meant it could go digging in the database, that could be problematic.
But eh, this really is an edge case and by the by.
Comment #3
bojanz commentedIt's still an edit.
In general, I don't think the entity form should ever care about #op, or go digging in the db. But I won't try to prevent anyone from shooting themselves in the foot :)
Do we have any issue here then? Or was it just about the edge case?
Comment #4
joachim commentedYup -- is $entity_form[#op] as found in EntityInlineEntityFormController::entityForm about the outer form, or the inner form being defined in that method?
I was hoping to use the op -- if it's about the inner form -- to pass on to a regular entity form, as part of #1660802: add a controller for 'standard' EntityAPI entities.
Basically, if it does describe the inner form, it's got a bug.
If it doesn't describe the inner form, should it be renamed / documented / both?
Comment #5
bojanz commentedIt's about the inner form.
And I don't know how it can be wrong:
Comment #6
joachim commentedHmm, nor can I. Just checked again and it's fine. I must have got confused in all the debug output I had flying around. Apologies for the noise.
Comment #7
guypaddock commentedRe-opening. I'm still experiencing this issue, even in dev.
Editing and saving another variation while the form to add a new variation is open can cause the new variation to be saved prematurely.
Steps to Reproduce
Expected Results
The product display will have two variations -- the one added in #2, and the one started in #3.
Actual Results
The product display has three variations -- the one added in #2, and two copies of the one added in #3. Saving the product display results in a SQL constraint violation.
If I debug the code, it looks like
inline_entity_form_process_entity_form()is invoked twice when the edit form is saved, once for the edit form, and a second time for the add form, even though only the edit form was really saved. And, in each case, "op" matches the button of the form being processed rather than the name of the real button that was clicked (i.e. when the function is processing the edit form, "op" is "edit"; then, when it processes the add form in the same request, "op" is suddenly "add").Comment #8
guypaddock commentedAttached is a patch that corrects the following issues:
Comment #9
guypaddock commentedOne thought: my patch doesn't actually make #op more useful, it just doesn't rely on it as the only way to tell what form is being submitted.
Comment #10
guypaddock commentedRevised the patch -- IEF wasn't saving any entities that were open for editing when the overall node edit form was saved.
Comment #11
guypaddock commentedOne more try: this fixes an issue where variations open for editing could be saved prematurely when a new variation was added.
This version also makes the conditional a bit easier to read by storing values in variables.
Comment #12
bojanz commentedThis will be handled in #2032649: Rework inline form submission.