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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 2941561-allow_form_ajax_exception-8.patch | 5.28 KB | dobe |
| #5 | 2941561-allow_form_ajax_exception-5.patch | 891 bytes | hydra |
| #2 | 2941561-allow_form_ajax_exception-2.patch | 895 bytes | Patrick Bauer |
Comments
Comment #2
Patrick Bauer commentedPatch provided, rethrowing the FormAjaxException if encountered.
Comment #3
Angry Dan commentedThis 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.phpneeds reconsidering.Finally, watch out for
EnforcedResponseExceptionwhich also appears to be a thing that could trip you up.Comment #4
Patrick Bauer commentedI agree the underlying form ajax system should be fixed.
Comment #5
hydra commentedJust 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.
Comment #7
webdesgnr14 commentedHey 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.
Comment #8
dobe commentedI 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.
Comment #9
wim leersI 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.
Comment #10
wim leersComment #11
wim leersTurns 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!