From 21c5450568281e9c2170b6a528bb1ff93eb5ea3d Mon Sep 17 00:00:00 2001 From: magentix Date: Thu, 13 Apr 2023 10:11:39 +0200 Subject: [PATCH] Fix form validator when Turnstile is disabled --- CHANGELOG.md | 1 + Observer/Validate.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32e9325..7f07416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Config path updated - CSP Whitelist added +- Fix form validator when Turnstile is disabled ## 100.1.1 diff --git a/Observer/Validate.php b/Observer/Validate.php index 23505bb..b8f10ed 100644 --- a/Observer/Validate.php +++ b/Observer/Validate.php @@ -28,6 +28,7 @@ use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Session\Generic; use Magento\Review\Controller\Product\Post as ReviewPost; +use PixelOpen\CloudflareTurnstile\Helper\Config; use PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms; use PixelOpen\CloudflareTurnstile\Model\Validator; @@ -47,6 +48,8 @@ class Validate implements ObserverInterface protected Json $json; + protected Config $config; + /** * @param ManagerInterface $messageManager * @param Response $response @@ -55,6 +58,7 @@ class Validate implements ObserverInterface * @param Generic $reviewSession * @param Validator $validator * @param Json $json + * @param Config $config */ public function __construct( ManagerInterface $messageManager, @@ -63,7 +67,8 @@ public function __construct( CustomerSession $customerSession, Generic $reviewSession, Validator $validator, - Json $json + Json $json, + Config $config ) { $this->messageManager = $messageManager; $this->response = $response; @@ -72,6 +77,7 @@ public function __construct( $this->reviewSession = $reviewSession; $this->validator = $validator; $this->json = $json; + $this->config = $config; } /** @@ -130,6 +136,9 @@ public function getCfResponse(Request $request, ActionInterface $action): ?strin */ public function canValidate(Request $request, ActionInterface $action): bool { + if (!$this->config->isEnabled()) { + return false; + } if (!$request->isPost()) { return false; }