Using Drupal's #ajax in embedded entity forms (e.g. contact forms) doesn't work.
The EntityEmbedFilter catches all exceptions without letting FormAjaxException through, which is used to handle form ajax request.

Comments

Patrick Bauer created an issue. See original summary.

Patrick Bauer’s picture

StatusFileSize
new895 bytes

Patch provided, rethrowing the FormAjaxException if encountered.

Angry Dan’s picture

This is all kinds of messed up, but to be honest you should probably stop catching those exceptions all together - having code that just sucks up exceptions like that usually leads to obvious problems being converted into obscure behaviours.

That being said - exceptions are absolutely not meant to be used as a messaging system, nor are they intended as a replacement for goto statements. Really the behaviour of Drupal/Core/Form/FormBuilder.php needs reconsidering.

Finally, watch out for EnforcedResponseException which also appears to be a thing that could trip you up.

Patrick Bauer’s picture

I agree the underlying form ajax system should be fixed.

hydra’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new891 bytes

Just rerolled the patch.
Since we cannot "just fix" this in core that easy, it should be fixed in entity_embed. As long as the ajax system works that way, we should go alongside core and fix the "bug" in contrib.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 5: 2941561-allow_form_ajax_exception-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

webdesgnr14’s picture

Hey there,

I've used this patch and it has worked up until now ... i'm experiencing this error:

Drupal\Core\Form\FormAjaxException: in Drupal\Core\Form\FormBuilder->buildForm() (line 337 of /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php).

Any help is appreciated.

dobe’s picture

StatusFileSize
new5.28 KB

I agree with @Angry Dan. I removed the Try/Catch in this patch. Which has allowed me to embed a Commerce Product with Variations and now it updates using ajax. It likely needs to be addressed in core. There is no issue shared here for that though.

wim leers’s picture

Title: FormAjaxException not getting through » Some exceptions not getting through, such as FormAjaxException, preventing e.g. Commerce Products with Variations from being embedded
Issue tags: +Media Initiative
Related issues: +#2748581: Embedding core Contact forms

I don't think Entity Embed should support embedding core contact forms (#2748581: Embedding core Contact forms). but embedding Commerce Products with Variations definitely does seem crucial.

What this still needs is test coverage.

wim leers’s picture

Issue tags: +Needs tests
wim leers’s picture

Status: Needs work » Closed (duplicate)

Turns out #3055050: Loosen EntityEmbedFilter's greedy exception capture: catch only relevant exceptions reported the same problem as this, but solved it in a much simpler way; so simple that I felt confident committing it without test coverage.

Sorry. But what matters most for sure is that this problem is fixed! :)

Closing this as a duplicate now!