Problem/Motivation

Drupal core has various RedirectResponse items that allow us to return a redirect response for any request. However, there is no convention for stopping the current execution stack and immediately redirecting. Core follows this pattern in \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber.

The subscriber listens to KernelEvents::EXCEPTION. If there is a FormAjaxException it considers the request OK and sets the response. This allows AJAX requests to be returned without going through unneeded processes.

We need this to handle offsite payments.

Proposed resolution

Create a RedirectResponse exception and event subscriber. Check if the exception is ours and redirect as needed.

Remaining tasks

  1. Write exception and subscriber
  2. Write tests

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review

  • bojanz committed 263050c on 8.x-2.x
    Issue #2753831 by mglaman: Add the ability to throw a redirect exception
    
bojanz’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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