I'm trying to use the entity embed module to embed core Contact forms.
I have an entity embed button with the following:
Embed type: Entity
Entity type: Contact form
This works in displaying the form on the node, along with being able to be filled in & submitted successfully. However there are two resulting issues:
1) The form is submitted twice. I'm guessing this is once when the form is submitted normally, then a second time when entity_embed tries to render the form again? Duplicate form submission caused by Metatag module.
2) After submission, the form isn't rendered again. I've looked, and it's because of (by default) the contact form submit returns a Redirect Response (EnforcedResponseException) rather than the renderable form array. This triggers the try/catch in EntityEmbedFilter::process(). Disabling the redirect results in the form displaying, but leaves all form values filled in.
Has anybody used this with the core Contact module? Would this use case require specific filters etc. - if so, can anyone point me in the right direction of what needs to be done so I can take a stab at this?
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2748581-more-specific-catch-18.patch | 754 bytes | nadavoid |
| #11 | 2748581-more-specific-catch-11.patch | 753 bytes | volkerk |
| #9 | 2748581-more-specific-catch-9.patch | 903 bytes | volkerk |
| #4 | 2748581-more-specific-catch.patch | 601 bytes | volkerk |
Comments
Comment #2
smazOk, I've found out why the duplicate submissions: Metatag module is generating the Description tag for the page based on the teaser. When it renders the teaser, it's re-triggering the form submission when entity_embed brings in the form during filter processing.
Comment #3
hanzoz commentedHey,
I've the same issue where if the form was being embedded to a page and after the user submit, the "Redirect Page" value is not working.
really need some assistance for this issue
Comment #4
volkerk commentedOnly catch the exception type (EntityNotFoundException) which is thrown in EntityEmbedFilter.
Comment #5
volkerk commentedComment #6
slashrsm commentedCan someone confirm that #4 solves the problem?
Comment #8
smazI've just tested #4, and and it does fix the issue.
I have:
** before patching **
1) Created an entity embed button for contact forms, and added it to a text format (Full HTML)
2) Created a node, and embedded the 'Website feedback' contact form
3) Submitted the embedded form, and verified it reloaded the current page but without the form, as per the original issue
** after patching **
4) Re-submitted the embedded form, and was redirected to the homepage (default for that form) with the submission message displayed
5) Updated the contact form to set the redirect to a custom node
6) Resubmitted the embedded form, and was redirected to the specified node with the submission message displayed
That's great, thank you for the patch!
However, I've set it to needs work instead of RTBC because:
I've also not tested with embedding YAML Forms, but that could be a separate issue if it doesn't work with that - the main thing is working with the core Contact module.
Comment #9
volkerk commentedI improved the patch to also catch the RecursiveRenderingException which is thrown some lines up.
IMHO it's generally a good idea to only catch exceptions which you throw, form redirection is done using an EnforcedResponseException, which was catched here, therefore breaking the redirect and proving my point.
Comment #11
volkerk commentedComment #12
slashrsm commentedShould we rather have multiple catch statements?
Comment #13
smazI've just done some more testing - I realised the version I was testing against before was 8.0-alpha1, not the latest dev like I thought. Apologies.
It looks like Contact forms can no longer be selected in the 'Entity type' list, because it doesn't have a view builder. This commit fixed the check for view builders.
I'm not sure what could be done to allow entities that don't have view builders, if anything?
Comment #14
slashrsm commentedNothing :). It is up to the entity type to provide it. Contact storage module adds view builder for contact forms. What happens if you enable it?
Comment #15
smazThat allows 'Contact form' to be selected as an entity type, but only has two display options - Entity ID or Label, which just output the string for id / label when embedded.
Does that mean we'll need to look at creating a module to provide a view builder for contact forms that's suitable for Entity Embed? If so I can try & take a punt at it.
Cheers
Comment #16
slashrsm commentedIt seems that the problem is the fact that config entities use pseudo view mode "Default", which doesn't actually exist. We could try to add support for that in \Drupal\entity_embed\Plugin\Derivative\ViewModeDeriver. Check if default view mode exist and create plugin derivative for the pseudo view mode if not.
Comment #17
volkerk commentedI already created an issue for the 'rendered entity formatter' vs 'view mode' problem, see https://www.drupal.org/node/2796269.
Anyway I think this bug should be fixed on it's own, if you prefer separate catch statements we could rewrite it.
Comment #18
nadavoid commentedRerolled the patch in #11 against the latest dev, commit bdb4e9d
Comment #20
wim leers#14++
I'd also be very careful to use Entity Embed to embed forms: Drupal's forms are highly dynamic, interactive pieces of content (in the sense that they require communication with the server), whereas generally "viewing an entity" means it's something static, something to be read/consumed.
I think arguably, this is working as designed.
Comment #21
wim leersMonths have passed, #3055050: Loosen EntityEmbedFilter's greedy exception capture: catch only relevant exceptions fixed this :)