Skip to content

Commit

Permalink
Read captcha config from Backend Field config
Browse files Browse the repository at this point in the history
  • Loading branch information
chrode committed Jul 10, 2024
1 parent 4e72dd5 commit 060a625
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Classes/ViewHelpers/Form/ParseConfigurationViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace Slub\SlubForms\ViewHelpers\Form;

use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

class ParseConfigurationViewHelper extends AbstractViewHelper {


/**
* Register arguments.
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('configurationString', 'string', 'Config string', true);

}

/**
* @return string
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {

$templateVariableContainer = $renderingContext->getVariableProvider();

if ($templateVariableContainer->exists('configuration')) {
$templateVariableContainer->remove('configuration');
}
$templateVariableContainer->add('configuration', \Slub\SlubForms\Helper\ArrayHelper::configToArray($arguments['configurationString']));

return $renderChildrenClosure();

}


}
5 changes: 4 additions & 1 deletion Resources/Private/Partials/Forms/Captcha.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{namespace sf=Slub\SlubForms\ViewHelpers}
<script
type="module"
src="https://cdn.jsdelivr.net/npm/[email protected]/widget.module.min.js"
Expand All @@ -9,7 +10,9 @@

<div class="field_description">
<f:form.hidden name="field[{fieldset.uid}][{field.uid}]" class="{field.shortname}" />
<div class="frc-captcha" data-sitekey="FCMLJCSR6Q54F53S" data-lang="de" data-start="auto" data-solution-field-name="tx_slubforms_sf[field][{fieldset.uid}][{field.uid}]"></div>
<f:format.raw><sf:form.parseConfiguration configurationString="{field.configuration}">
<div class="frc-captcha" data-sitekey="{configuration.sitekey}" data-lang="de" data-start="auto" data-solution-field-name="tx_slubforms_sf[field][{fieldset.uid}][{field.uid}]"></div>
</sf:form.parseConfiguration></f:format.raw>

<label class="error" for="tx_slubforms_sf[field][{fieldset.uid}][{field.uid}]"></label>
</div>

0 comments on commit 060a625

Please sign in to comment.