diff --git a/Classes/Validation/Validator/AbstractCaptchaValidator.php b/Classes/Validation/Validator/AbstractCaptchaValidator.php index cd7595f..23c7e64 100644 --- a/Classes/Validation/Validator/AbstractCaptchaValidator.php +++ b/Classes/Validation/Validator/AbstractCaptchaValidator.php @@ -4,7 +4,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator; abstract class AbstractCaptchaValidator extends AbstractValidator @@ -23,18 +22,15 @@ abstract class AbstractCaptchaValidator extends AbstractValidator /** * @var array Extension TypoScript */ - protected $settings; + protected array $settings; - public function __construct(array $options = array()) + public function __construct(ConfigurationManagerInterface $configurationManager) { - parent::__construct($options); - /** @var ObjectManager $objectManager */ - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); - /** @var ConfigurationManagerInterface $configurationManager */ - $configurationManager = $objectManager->get(ConfigurationManagerInterface::class); +// /** @var ConfigurationManagerInterface $configurationManager */ +// $configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class); $this->settings = $configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, - 'JhCaptcha' + 'JhCaptcha', ); } @@ -43,11 +39,9 @@ public function __construct(array $options = array()) * * @param string $translateKey * @param int $code The error code (a unix timestamp) - * @param array $arguments Arguments to be replaced in message - * @param string $title title of the error */ - protected function addError($translateKey, $code, array $arguments = [], $title = '') + protected function addTranslatedError(string $translateKey, int $code): void { - parent::addError($this->translateErrorMessage($translateKey, 'jh_captcha'), $code); + $this->addError($this->translateErrorMessage($translateKey, 'jh_captcha'), $code); } } diff --git a/Classes/Validation/Validator/ReCaptchaValidator.php b/Classes/Validation/Validator/ReCaptchaValidator.php index d3724a6..a97c514 100644 --- a/Classes/Validation/Validator/ReCaptchaValidator.php +++ b/Classes/Validation/Validator/ReCaptchaValidator.php @@ -12,7 +12,7 @@ class ReCaptchaValidator extends AbstractCaptchaValidator * * @param mixed $value */ - protected function isValid($value) + protected function isValid(mixed $value): void { if ($this->settings['reCaptcha']['version'] == 2) { $secret = htmlspecialchars($this->settings['reCaptcha']['v2']['secretKey']); @@ -31,34 +31,34 @@ protected function isValid($value) foreach ($apiResponse['error-codes'] as $errorCode) { switch ($errorCode) { case 'missing-input-secret': - $this->addError('missingInputSecret', 1426877004); + $this->addTranslatedError('missingInputSecret', 1426877004); break; case 'invalid-input-secret': - $this->addError('invalidInputSecret', 1426877455); + $this->addTranslatedError('invalidInputSecret', 1426877455); break; case 'missing-input-response': - $this->addError('missingInputResponse', 1426877525); + $this->addTranslatedError('missingInputResponse', 1426877525); break; case 'invalid-input-response': - $this->addError('invalidInputResponse', 1426877590); + $this->addTranslatedError('invalidInputResponse', 1426877590); break; case 'bad-request': - $this->addError('badRequest', 1426877490); + $this->addTranslatedError('badRequest', 1426877490); break; case 'timeout-or-duplicate': - $this->addError('timeoutOrDuplicate', 1426877420); + $this->addTranslatedError('timeoutOrDuplicate', 1426877420); break; default: - $this->addError('defaultError', 1427031929); + $this->addTranslatedError('defaultError', 1427031929); } } } else { - $this->addError('defaultError', 1427031929); + $this->addTranslatedError('defaultError', 1427031929); } } else { if ($this->settings['reCaptcha']['version'] != 2 && isset($apiResponse['score'])) { if ($apiResponse['score'] < $this->settings['reCaptcha']['v3']['minimumScore']) { - $this->addError('scoreError', 1541173838); + $this->addTranslatedError('scoreError', 1541173838); } } } diff --git a/Classes/ViewHelpers/ReCaptchaViewHelper.php b/Classes/ViewHelpers/ReCaptchaViewHelper.php index 246dd84..803ad02 100644 --- a/Classes/ViewHelpers/ReCaptchaViewHelper.php +++ b/Classes/ViewHelpers/ReCaptchaViewHelper.php @@ -14,15 +14,9 @@ class ReCaptchaViewHelper extends \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractView */ protected $escapeOutput = false; - /** - * @var ConfigurationManagerInterface - */ - protected $configurationManager; + protected ConfigurationManagerInterface $configurationManager; - /** - * @param ConfigurationManagerInterface $configurationManager - */ - public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) + public function __construct(ConfigurationManagerInterface $configurationManager) { $this->configurationManager = $configurationManager; } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..0c2fff8 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,11 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + Haffner\JhCaptcha\: + resource: '../Classes/*' + exclude: + - '../Classes/**/{Model,Exception}/*' + diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index 6316bbf..24aa76c 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,5 +1,4 @@ \ No newline at end of file diff --git a/composer.json b/composer.json index 79bc445..b65a00b 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "docs": "https://docs.typo3.org/typo3cms/extensions/jh_captcha/" }, "require": { - "typo3/cms-core": "^10.4 || ^11.5" + "typo3/cms-core": "^10.4 || ^11.5 || ^12.4" }, "replace": { "typo3-ter/jh_captcha": "self.version" diff --git a/ext_localconf.php b/ext_localconf.php index 2606218..258b926 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,6 @@ registerIcon( 't3-form-icon-jhcaptcha-recaptcha', - \TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider::class, - ['name' => 'google'] + \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class, + ['source' => 'EXT:jh_captcha/Resources/Public/Icons/google.svg'] ); # EXT:powermail