Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Classes/ViewHelpers/ReCaptchaViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RH\RhRecaptcha\ViewHelpers;

/*
Expand Down Expand Up @@ -47,6 +48,7 @@ class ReCaptchaViewHelper extends AbstractViewHelper implements SingletonInterfa

/**
* @param ConfigurationManagerInterface $configurationManager
*
* @return void
*/
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
Expand Down Expand Up @@ -93,24 +95,25 @@ public function render()
throw new InvalidVariableException('No siteKey provided in TypoScript constants', 1358349150);
}

if (!$this->initialized) {
if ( ! $this->initialized) {
$key = $reCaptchaSettings['siteKey'];
$this->initialized = true;
$pageRenderer = $this->getPageRenderer();
$pageRenderer->addJsFooterInlineCode(
'recaptcha',
'
var recaptchaCallback = function() {
for (var i = 1; i <= 1000; ++i) {
if (document.getElementById(\'g-recaptcha-\' + i)) {
grecaptcha.render(\'g-recaptcha-\' + i, {\'sitekey\' : \'' . $key . '\'});
}
}
};
/*]]>*/
</script>
<script src="https://www.google.com/recaptcha/api.js?hl=' . $reCaptchaSettings['lang'] . '&onload=recaptchaCallback&render=explicit"
async defer data-ignore="1">/*<![CDATA[*/
var recaptchaCallback = function() {
var tx_recaptcha__elements = document.getElementsByClassName("g-recaptcha");
if (tx_recaptcha__elements.length > 0) {
for (i = 0; i < tx_recaptcha__elements.length; i++) {
grecaptcha.render(tx_recaptcha__elements[i].getAttribute("id"), {\'sitekey\' : \'' . $key . '\'});
}
}
};
/*]]>*/
</script>
<script src="https://www.google.com/recaptcha/api.js?hl=' . $reCaptchaSettings['lang'] . '&onload=recaptchaCallback&render=explicit"
async defer data-ignore="1">/*<![CDATA[*/
',
false,
true
Expand Down