The code that triggers #ief_element_submit callbacks is attached once in hook_form_alter() to cover IEF widgets, and once in the InlineEntityForm #process, to cover IEF form elements. This results in the code being run once for the widgets, and once for each IEF form element. That's why dawehner had to add array_unique() to the attach code, the callbacks were getting duplicated.

My initial idea was to make sure ElementSubmit::attach is called from only one place, hook_form_alter(). Of course, the form alter doesn't detect IEF form elements because they're created in #process. The only callback that runs after #process is #after_build, but at that point it's too late to add submit callbacks.

So, a few hours later, back to the drawing board. We keep hook_form_alter() as it is, clean up the attaching in the form element (but keep it out of necessity), make sure ElementSubmit::attach is smart enough to run only once.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

tedbow’s picture

Status: Active » Needs review
FileSize
1.49 KB

Here is an idea around keeping track of which forms have already done ElementSubmit::attach via build form id.

The build form id does seem to change with ajax calls but the submit callback are also gone and need to re-attached.

bojanz’s picture

Status: Needs review » Fixed

Thanks, that gave me the idea of simply putting the build in in form state.

Addressed as a part of the cleanup in https://github.com/bojanz/inline_entity_form/commit/05fd711ac6404954f2ae...
The code feels much clearer now.

Status: Fixed » Closed (fixed)

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