Create event to modify response

Created on 28 January 2022, over 2 years ago
Updated 17 January 2024, 5 months ago

Problem/Motivation

We need to be able to modify the response on forms submissions to add extra information, success message or custom validations.
The issue #3137074 ✨ Create hook_alter to modify response for success and errors Fixed was propose to create a hook_alter and this issue has a similar approach but using Events.

Proposed resolution

I'm proposing to create an Event to give the possibility to a Subscriber modify the return data, this Event will have the Type (Slug for success or error), Submission Data, Response Data and Http Code.

The Response Data and Http Code will be passed by reference to can be changed before Response.

Remaining tasks

The code that I sent has a dependency of #3165659 πŸ› Webform handlers gets called twice on WebformSubmission POST Fixed

✨ Feature request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil viniciusrp

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡°Denmark rimi@aarhus.dk

    @dgaspara @nsalves, any hope that we can see this (or something similar) in the Webform REST module in the near future? It will make an excellent module even better.

  • πŸ‡΅πŸ‡ΉPortugal nsalves

    Hey everyone,
    Had to do a couple of changes to make the patch work, some new responses were sent and there was need to change the order of the arguments in the dispatch method to support newer versions of Symfony. Nevertheless looks good and committed to the dev branch. A new release will be issue soon

  • Status changed to Fixed 7 months ago
  • πŸ‡΅πŸ‡ΉPortugal nsalves
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 5 months ago
  • πŸ‡΅πŸ‡±Poland Pozi

    By using "Drupal\Component\EventDispatcher\Event" minimum version requirement should not be "^8.7.7 || ^9 || ^10" but "^9.1 || ^10".

    Or we can introduce similar apporach as web/modules/contrib/commerce/src/EventBase.php commerce module took:

    <?php
    
    namespace Drupal\commerce;
    
    // Drupal\Component\EventDispatcher\Event was introduced in Drupal core 9.1 to
    // assist with deprecations and the transition to Symfony 5.
    // @todo Remove this when core 9.1 is the lowest supported version.
    // @see https://www.drupal.org/project/commerce/issues/3192056
    if (!class_exists('Drupal\Component\EventDispatcher\Event')) {
      class_alias('Symfony\Component\EventDispatcher\Event', 'Drupal\Component\EventDispatcher\Event');
    }
    
    use Drupal\Component\EventDispatcher\Event;
    
    /**
     * Provides a base event class for Commerce events.
     */
    class EventBase extends Event {}
    
    
Production build 0.69.0 2024