From 1cb46c77443c1e94d4954597daa829db5dd30c6c Mon Sep 17 00:00:00 2001 From: Benjamin Kott Date: Tue, 12 Oct 2021 15:31:02 +0200 Subject: [PATCH] [BUGFIX] Allow to overwrite properties of google captcha --- Classes/Domain/Factory/CommentFormFactory.php | 15 ++++++++++----- ...{GoogleCaptcha.html => BlogGoogleCaptcha.html} | 0 2 files changed, 10 insertions(+), 5 deletions(-) rename Resources/Private/Partials/Form/{GoogleCaptcha.html => BlogGoogleCaptcha.html} (100%) diff --git a/Classes/Domain/Factory/CommentFormFactory.php b/Classes/Domain/Factory/CommentFormFactory.php index 9ce902ba..52b80a5b 100644 --- a/Classes/Domain/Factory/CommentFormFactory.php +++ b/Classes/Domain/Factory/CommentFormFactory.php @@ -12,6 +12,7 @@ use T3G\AgencyPack\Blog\Domain\Finisher\CommentFormFinisher; use T3G\AgencyPack\Blog\Domain\Validator\GoogleCaptchaValidator; +use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; @@ -43,9 +44,13 @@ public function build(array $configuration, string $prototypeName = null): FormD $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $formConfigurationService = $objectManager->get(ConfigurationService::class); $prototypeConfiguration = $formConfigurationService->getPrototypeConfiguration($prototypeName); - $prototypeConfiguration['formElementsDefinition']['GoogleCaptcha'] = [ - 'implementationClassName' => 'TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement' - ]; + $prototypeConfiguration['formElementsDefinition']['BlogGoogleCaptcha'] = $prototypeConfiguration['formElementsDefinition']['BlogGoogleCaptcha'] ?? []; + ArrayUtility::mergeRecursiveWithOverrule( + $prototypeConfiguration['formElementsDefinition']['BlogGoogleCaptcha'], + [ + 'implementationClassName' => 'TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement' + ] + ); $configurationManager = $objectManager->get(ConfigurationManagerInterface::class); $blogSettings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog'); @@ -58,7 +63,7 @@ public function build(array $configuration, string $prototypeName = null): FormD $form->setRenderingOption('controllerAction', 'form'); $form->setRenderingOption('submitButtonLabel', LocalizationUtility::translate('form.comment.submit', 'blog')); $renderingOptions = $form->getRenderingOptions(); - $renderingOptions['partialRootPaths'][] = 'EXT:blog/Resources/Private/Partials/Form/'; + $renderingOptions['partialRootPaths'][-1634043971] = 'EXT:blog/Resources/Private/Partials/Form/'; $form->setRenderingOption('partialRootPaths', $renderingOptions['partialRootPaths']); $page = $form->createPage('commentform'); @@ -88,7 +93,7 @@ public function build(array $configuration, string $prototypeName = null): FormD $explanationText->setProperty('text', LocalizationUtility::translate('label.required.field', 'blog') . ' ' . LocalizationUtility::translate('label.required.field.explanation', 'blog')); if ($captcha['enable'] && $captcha['sitekey'] && $captcha['secret']) { - $captchaField = $page->createElement('captcha', 'GoogleCaptcha'); + $captchaField = $page->createElement('captcha', 'BlogGoogleCaptcha'); $captchaField->setProperty('sitekey', $captcha['sitekey']); $captchaField->addValidator($objectManager->get(GoogleCaptchaValidator::class)); } diff --git a/Resources/Private/Partials/Form/GoogleCaptcha.html b/Resources/Private/Partials/Form/BlogGoogleCaptcha.html similarity index 100% rename from Resources/Private/Partials/Form/GoogleCaptcha.html rename to Resources/Private/Partials/Form/BlogGoogleCaptcha.html