From 7cef730c51983e6ffcf6b082e106b8ee21131487 Mon Sep 17 00:00:00 2001 From: Charles Sharp Date: Mon, 8 Jun 2026 13:25:52 -0600 Subject: [PATCH 1/3] Add RedirectInterface to Validate class If submitting a form ajax style from a web page, the original redirect would be eaten and any messages to the messageManager would not show up until manually reloading page. Using Magento RedirectInterface to do the redirect will then show the MessageManager messages on the page without a forced page reload. --- Observer/Validate.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Observer/Validate.php b/Observer/Validate.php index 1b56cdc..2a9ab5d 100644 --- a/Observer/Validate.php +++ b/Observer/Validate.php @@ -14,6 +14,7 @@ use Magento\Framework\App\ActionInterface; use Magento\Framework\App\Request\Http as Request; use Magento\Framework\App\Response\Http as Response; +use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Message\ManagerInterface; @@ -29,6 +30,8 @@ abstract class Validate implements ObserverInterface protected Response $response; + protected RedirectInterface $redirect; + protected Validator $validator; protected Json $json; @@ -55,6 +58,7 @@ abstract class Validate implements ObserverInterface public function __construct( ManagerInterface $messageManager, Response $response, + RedirectInterface $redirect, Validator $validator, Json $json, Config $config, @@ -63,6 +67,7 @@ public function __construct( ) { $this->messageManager = $messageManager; $this->response = $response; + $this->redirect = $redirect; $this->validator = $validator; $this->json = $json; $this->config = $config; @@ -114,9 +119,7 @@ public function getCfResponse(): ?string protected function error(Phrase $message): void { $this->messageManager->addErrorMessage($message); - $this->response->setRedirect($this->request?->getServer('HTTP_REFERER', '/') ?? '/'); - - $this->response->sendResponse(); + $this->redirect->redirect($this->action->getResponse(), $this->redirect->getRefererUrl()); exit(); } From 8a752d2a22739992660c5ec1956ba95d34ad79b4 Mon Sep 17 00:00:00 2001 From: Charles Sharp Date: Mon, 8 Jun 2026 13:27:12 -0600 Subject: [PATCH 2/3] Add RedirectInterface to Frontend.php constructor If submitting a form ajax style from a web page, the original redirect would be eaten and any messages to the messageManager would not show up until manually reloading page. Using Magento RedirectInterface to do the redirect will then show the MessageManager messages on the page without a forced page reload. --- Observer/Validate/Frontend.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Observer/Validate/Frontend.php b/Observer/Validate/Frontend.php index 86f3e84..b2b0f8c 100644 --- a/Observer/Validate/Frontend.php +++ b/Observer/Validate/Frontend.php @@ -13,6 +13,7 @@ use Magento\Customer\Controller\Ajax\Login as AjaxLoginPost; use Magento\Customer\Model\Session as CustomerSession; use Magento\Framework\App\Response\Http as Response; +use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; use Magento\Framework\Serialize\Serializer\Json; @@ -38,6 +39,7 @@ class Frontend extends Validate public function __construct( ManagerInterface $messageManager, Response $response, + RedirectInterface $redirect, Validator $validator, Json $json, Config $config, @@ -47,7 +49,7 @@ public function __construct( ) { $this->customerSession = $customerSession; - parent::__construct($messageManager, $response, $validator, $json, $config, $persistor, $data); + parent::__construct($messageManager, $response, $redirect, $validator, $json, $config, $persistor, $data); } From 2c83ab0ecf150596478b4a7446ce631ed59313e0 Mon Sep 17 00:00:00 2001 From: charles sharp Date: Tue, 9 Jun 2026 11:07:14 -0600 Subject: [PATCH 3/3] remove response dependency inject from validator constructor to satisfy constructor argument limit. response is fetched from controller action in execute function. also remove response dependency inject from frontend to fit inheritance structure of parent changes. response will be set in parent execute method. --- Observer/Validate.php | 11 +++++------ Observer/Validate/Frontend.php | 7 ++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Observer/Validate.php b/Observer/Validate.php index 2a9ab5d..5ad0ca3 100644 --- a/Observer/Validate.php +++ b/Observer/Validate.php @@ -48,7 +48,6 @@ abstract class Validate implements ObserverInterface /** * @param ManagerInterface $messageManager - * @param Response $response * @param Validator $validator * @param Json $json * @param Config $config @@ -57,7 +56,6 @@ abstract class Validate implements ObserverInterface */ public function __construct( ManagerInterface $messageManager, - Response $response, RedirectInterface $redirect, Validator $validator, Json $json, @@ -66,7 +64,6 @@ public function __construct( array $data = [] ) { $this->messageManager = $messageManager; - $this->response = $response; $this->redirect = $redirect; $this->validator = $validator; $this->json = $json; @@ -83,8 +80,9 @@ public function __construct( */ public function execute(Observer $observer): void { - $this->action = $observer->getEvent()->getData('controller_action'); - $this->request = $observer->getEvent()->getData('request'); + $this->action = $observer->getEvent()->getData('controller_action'); + $this->request = $observer->getEvent()->getData('request'); + $this->response = $this->action->getResponse(); if ($this->canValidate()) { try { @@ -119,7 +117,8 @@ public function getCfResponse(): ?string protected function error(Phrase $message): void { $this->messageManager->addErrorMessage($message); - $this->redirect->redirect($this->action->getResponse(), $this->redirect->getRefererUrl()); + $this->redirect->redirect($this->response, $this->redirect->getRefererUrl()); + exit(); } diff --git a/Observer/Validate/Frontend.php b/Observer/Validate/Frontend.php index b2b0f8c..667c6a0 100644 --- a/Observer/Validate/Frontend.php +++ b/Observer/Validate/Frontend.php @@ -12,7 +12,6 @@ use Magento\Customer\Controller\Ajax\Login as AjaxLoginPost; use Magento\Customer\Model\Session as CustomerSession; -use Magento\Framework\App\Response\Http as Response; use Magento\Framework\App\Response\RedirectInterface; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Phrase; @@ -28,7 +27,6 @@ class Frontend extends Validate /** * @param ManagerInterface $messageManager - * @param Response $response * @param Validator $validator * @param Json $json * @param Config $config @@ -38,9 +36,8 @@ class Frontend extends Validate */ public function __construct( ManagerInterface $messageManager, - Response $response, - RedirectInterface $redirect, Validator $validator, + RedirectInterface $redirect, Json $json, Config $config, CustomerSession $customerSession, @@ -49,7 +46,7 @@ public function __construct( ) { $this->customerSession = $customerSession; - parent::__construct($messageManager, $response, $redirect, $validator, $json, $config, $persistor, $data); + parent::__construct($messageManager, $redirect, $validator, $json, $config, $persistor, $data); }