After filling in the prompts with Drupal Console after executing drupal generate:event:subscriber
, and entering kernel.request
when prompted for the event name, it's possible to add something like the following to the callback function that handles the event:
use Symfony\Component\HttpFoundation\RedirectResponse;
...
/**
* This method is called whenever the kernel.request event is
* dispatched.
*
* @param GetResponseEvent $event
*/
public function kernelRequest(GetResponseEvent $event) {
$request = $event->getRequest();
$route_name = $request->attributes->get('_route');
if ($route_name == 'entity.checkout.canonical') {
// Create the destination URL, such as:
$url = Url::fromRoute('user.register')->toString();
// create redirect:
$response = new RedirectResponse($url);
$response->send();
}
}