From cc8fd6fa61f9948b1029c699f5d7eeb3a6f37d2e Mon Sep 17 00:00:00 2001 From: abid Date: Wed, 15 Sep 2021 12:21:48 +0200 Subject: [PATCH] [TASK] Make it possible to disable flash messages in MauticAuthorizeService --- Classes/Service/MauticAuthorizeService.php | 48 ++++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/Classes/Service/MauticAuthorizeService.php b/Classes/Service/MauticAuthorizeService.php index c88b879..9844563 100644 --- a/Classes/Service/MauticAuthorizeService.php +++ b/Classes/Service/MauticAuthorizeService.php @@ -37,6 +37,9 @@ class MauticAuthorizeService */ protected $minimumMauticVersion = '2.14.2'; + /** @var bool */ + protected $createFlashMessages = true; + public function __construct( array $extensionConfiguration = [], AuthInterface $authorization = null, @@ -58,7 +61,9 @@ public function validateCredentials(): bool || $this->extensionConfiguration['secretKey'] === '' || $this->extensionConfiguration['authorizeMode'] === '' ) { - $this->showCredentialsInformation(); + if ($this->createFlashMessages) { + $this->showCredentialsInformation(); + } return false; } @@ -91,13 +96,17 @@ public function checkConnection() $version = $api->getMauticVersion(); if ($version === null) { - $this->addErrorMessage(); + if ($this->createFlashMessages) { + $this->addErrorMessage(); + } return false; } if (version_compare($version, $this->minimumMauticVersion, '<')) { - $this->showIncorrectVersionInformation($version); + if ($this->createFlashMessages) { + $this->showIncorrectVersionInformation($version); + } return false; } @@ -117,12 +126,16 @@ public function checkConnection() } if (0 === strpos($this->extensionConfiguration['baseUrl'], 'http:')) { - $this->showInsecureConnectionInformation(); + if ($this->createFlashMessages) { + $this->showInsecureConnectionInformation(); + } return false; } - $this->showSuccessMessage(); + if ($this->createFlashMessages) { + $this->showSuccessMessage(); + } return true; } @@ -140,13 +153,15 @@ protected function showCredentialsInformation() $missingInformation[] = 'secretKey'; } - $this->addErrorMessage( - $this->translate('authorization.missingInformation.title'), - sprintf( - $this->translate('authorization.missingInformation.message'), - implode(', ', $missingInformation) - ) - ); + if ($this->createFlashMessages) { + $this->addErrorMessage( + $this->translate('authorization.missingInformation.title'), + sprintf( + $this->translate('authorization.missingInformation.message'), + implode(', ', $missingInformation) + ) + ); + } } public function authorize() @@ -170,7 +185,9 @@ public function authorize() HttpUtility::redirect($_SERVER['REQUEST_URI']); } } catch (\Exception $exception) { - $this->addErrorMessage((string)$exception->getCode(), (string)$exception->getMessage()); + if ($this->createFlashMessages) { + $this->addErrorMessage((string)$exception->getCode(), (string)$exception->getMessage()); + } return false; } @@ -288,4 +305,9 @@ public function accessTokenToBeRefreshed(): bool return false; } + + public function deactivateFlashMessages(): void + { + $this->createFlashMessages = false; + } }