Skip to content

Commit

Permalink
[BUGFIX] Allow to overwrite properties of google captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed Oct 12, 2021
1 parent 655d1cd commit 1cb46c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Classes/Domain/Factory/CommentFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 1cb46c7

Please sign in to comment.