diff --git a/Classes/EventListener/ModifyRegistrationValidatorResultEventListener.php b/Classes/EventListener/ModifyRegistrationValidatorResultEventListener.php new file mode 100644 index 0000000..b04bb5a --- /dev/null +++ b/Classes/EventListener/ModifyRegistrationValidatorResultEventListener.php @@ -0,0 +1,30 @@ +getSettings()['registration']['captcha'] ?? []; + $isCaptchaEnabled = isset($captchaSettings['enabled']) && $captchaSettings['enabled']; + $isBwCaptchaEnabled = isset($captchaSettings['type']) && $captchaSettings['type'] === 'bwCaptcha'; + + if (!$isCaptchaEnabled || !$isBwCaptchaEnabled) { + return; + } + + $validator = new ConjunctionValidator(); + $validator->addValidator(new NotEmptyValidator()); + $validator->addValidator(new CaptchaValidator()); + + $result = $validator->validate($event->getRegistration()->getCaptcha()); + + $event->getResult()->forProperty('captcha')->merge($result); + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index cef6323..1c719ec 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -10,3 +10,8 @@ services: Blueways\BwCaptcha\Middleware\Captcha: public: true + + Blueways\BwCaptcha\EventListener\ModifyRegistrationValidatorResultEventListener: + tags: + - name: event.listener + identifier: 'bw-captcha/sf-event-mgt-registration' \ No newline at end of file diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 3d6c2be..274b486 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -44,6 +44,15 @@ plugin.tx_bwcaptcha { } } +plugin.tx_sfeventmgt { + view { + partialRootPaths.999999 = EXT:bw_captcha/Resources/Private/SfEventMgt/ + } + settings.registration.captcha { + bwCaptcha < plugin.tx_bwcaptcha.settings + } +} + captcha = PAGE captcha { typeNum = 3413 diff --git a/README.md b/README.md index db7decc..0af920a 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,34 @@ plugin.tx_bwcaptcha { } ``` +### Usage in other Extensions + +#### sf_event_mgt + +To use the captcha element in the [sf_event_mgt](https://github.com/derhansen/sf_event_mgt/) extension, add the following TypoScript: + +``` +plugin.tx_sfeventmgt { + settings { + registration { + requiredFields = captcha + captcha { + enabled = 1 + type = bwCaptcha + } + } + } +} +``` + +If you want to override the shipped [BwCaptcha.html](https://github.com/maikschneider/bw_captcha/blob/main/Resources/Private/SfEventMgt/Registration/Captcha/BwCaptcha.html) partial, you need to configure the partialRootPaths with a higher index: + +``` +plugin.tx_sfeventmgt.view.partialRootPaths.9999999 = EXT:your_ext/Resources/Private/Partials/ +``` + +```yaml + ### Overriding the captcha element To override the captcha partial, copy it to your extension and add the partial path to diff --git a/Resources/Private/SfEventMgt/Registration/Captcha/BwCaptcha.html b/Resources/Private/SfEventMgt/Registration/Captcha/BwCaptcha.html new file mode 100644 index 0000000..c33ed19 --- /dev/null +++ b/Resources/Private/SfEventMgt/Registration/Captcha/BwCaptcha.html @@ -0,0 +1,61 @@ + + + +
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/composer.json b/composer.json index 5fc7bd2..28a4175 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,11 @@ "roave/security-advisories": "dev-latest", "typo3/cms-base-distribution": "^12.0", "typo3/cms-lowlevel": "^12.0", - "bk2k/bootstrap-package": "dev-master", + "bk2k/bootstrap-package": "^15.0", "friendsofphp/php-cs-fixer": "^3.12", "saschaegerer/phpstan-typo3": "^1.9", - "helhum/typo3-console": "^8.0" + "helhum/typo3-console": "^8.0", + "derhansen/sf_event_mgt": "^7.6" }, "extra": { "typo3/cms": {