Closed (fixed)
Project:
Webform
Version:
8.x-5.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2019 at 02:44 UTC
Updated:
28 Jun 2019 at 19:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jimkeller commentedThe attached patch uses a custom Event and EventSubscriber to perform a redirect if remote post fails in the RemotePostWebformHandler.
I really wanted to do this without having to explicitly call $response->send() in the event subscriber, but I could not find a way to get from the Plugin to either a controller, a form state, or an appropriate ResponseEvent that would let me simply return a $response or call setResponse().
I also tried using the EventSubscriber to catch a custom Exception, but found that to be tricky because the save() function of the base Entity class converts all uncaught Exceptions to EntityStorageException .
Comment #3
jrockowitz commentedComment #5
jrockowitz commentedA lot of people are currently using and relying on the RemotePost handler. Any changes would require test coverage to prevent any unexpected regressions.
I feel this functionality could easily be added by extending the RemotePost handler via a contrib/custom module. I am not sure the core webform module needs to provide this functionality.
Comment #6
jrockowitz commented@jimkeller Right now the most valuable contribution someone could make in regards to remote posting submission data is to document how to build a completely custom remote post handler since there is no way the webform module's core remote post handler can address every use case.
Comment #7
jimkeller commentedI contributed a similar patch for the D7 Webform Remote Post that took the approach of simply calling a hook when the POST failed ( https://www.drupal.org/project/webform_remote_post/issues/2787751 )
I took a different approach here because it was simple and because Webform seems to offer so many options out of the box (including redirecting to a thank you page). One more didn't seem like a big change but I agree that I might have a bit of an edge case.
Rather than build an entire custom post handler, which seems like overkill, could we trigger an event that could be subscribed to or call a hook on failure? Developers should be able to apply their own logic when a remote POST fails, which could include a redirect.
Comment #8
jrockowitz commentedAdding events to the remote post and possibly all handlers is a great and forward thinking idea. I am 100% onboard with doing this but we need to do it with test coverage.
Comment #9
jrockowitz commentedThe attached patch provides some initial support to redirect to a URL if Remote Post fails
Comment #11
jrockowitz commented@jimkeller I want to avoid adding any event subscribers until the pattern is well defined in Drupal core.
@see #3027625: Encourage the use of events over hooks
Your initial patch and comment about using Response->send() was very helpful. Thanks.
Comment #14
jrockowitz commentedI committed the patch. Please download the latest dev release to review.
For anyone needing additional custom error handling for remote posts, they should extend the RemotePostWebformHandler and override the handleError method.