From d09da90e11707cbac35c5e38aca31d9b03deed7e Mon Sep 17 00:00:00 2001
From: Merlin <merlin@geeks4change.net>
Date: Sun, 3 May 2020 19:16:56 +0200
Subject: [PATCH] Issue #2363189 by geek-merlin: Do not allow form builder
 functions to return Response objects

---
 core/lib/Drupal/Core/Form/FormBuilder.php | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php
index 4d1dc27f71..ee07ee7c6f 100644
--- a/core/lib/Drupal/Core/Form/FormBuilder.php
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -521,12 +521,8 @@ public function retrieveForm($form_id, FormStateInterface &$form_state) {
     // If the form returns a response, skip subsequent page construction by
     // throwing an exception.
     // @see Drupal\Core\EventSubscriber\EnforcedFormResponseSubscriber
-    //
-    // @todo Exceptions should not be used for code flow control. However, the
-    //   Form API currently allows any form builder functions to return a
-    //   response.
-    //   @see https://www.drupal.org/node/2363189
     if ($form instanceof Response) {
+      @trigger_error('Returning a response from a form builder function is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Throw a \Drupal\Core\Form\EnforcedResponseException instead. See https://www.drupal.org/node/2363189', E_USER_DEPRECATED);
       throw new EnforcedResponseException($form);
     }
     $form['#form_id'] = $form_id;
-- 
2.17.1

