Problem/Motivation

We need to modify the response for success and for errors on webform_rest submit

Proposed resolution

Implements hook_alter for these cases

CommentFileSizeAuthor
#10 3137074-for-4.0.1.patch3.83 KBviniciusrp
#2 3137074.patch2.15 KBrenatog
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RenatoG created an issue. See original summary.

renatog’s picture

Version: 8.x-3.x-dev » 8.x-2.0-beta2
FileSize
2.15 KB

Follow the patch in attachment. Please review.

Thanks

renatog’s picture

With this approach, all projects can modify responses with alter. Example:

function other_project_webform_rest_success_result_alter(&$values, &$response) {
 $values['hello'] = 'World';
}
andre.bonon’s picture

Works for me ! =)

It is really helpful for cases that you need to return a custom response.

Thanks!

andre.bonon’s picture

Status: Needs review » Reviewed & tested by the community
imclean’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Plugin/rest/resource/WebformSubmitResource.php
@@ -68,7 +68,13 @@ class WebformSubmitResource extends ResourceBase {
+      \Drupal::moduleHandler()->alter('webform_rest_error_result', $values, $response);

You can use dependency injection for the module handler service. There shouldn't be any calls to \Drupal:: outside procedural code.

renatog’s picture

Assigned: Unassigned » renatog

It really makes sense.

So the final result will be

$this->variableHandler->alter('webform_rest_error_result', $values, $response);

Ok, we'll do that.

Thanks

imclean’s picture

The service is module_handler so moduleHandler might be a better variable name.

anabpv’s picture

Assigned: renatog » anabpv

I'll work on this.

viniciusrp’s picture

FileSize
3.83 KB

I made a refactor at this patch to 4.0.1 version.
I'll work to create a version with Events to replace the hook_alter.

renatog’s picture

Version: 8.x-2.0-beta2 » 4.0.1
Status: Needs work » Reviewed & tested by the community

#10 really looks great to me. +1 to RTBC

anabpv’s picture

Assigned: anabpv » Unassigned
fadonascimento’s picture

+1 in favor to use Events instead of hook_alter see details:
https://www.drupal.org/project/webform_rest/issues/3261131

nsalves’s picture

Hey guys, we decided to go with the event approach described in (#3261131) since its more flexible and avoids the use of "drupalisms" so I'll be closing this ticket but thanks for the effort

nsalves’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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