Skip to content

Commit

Permalink
Merge pull request #293 from doenietzomoeilijk/fix-recaptcha-theme
Browse files Browse the repository at this point in the history
FIX, Recaptcha: Apply the theme from the config, or any theme at all
  • Loading branch information
bobdenotter committed Nov 6, 2019
2 parents 9228782 + 32fea9a commit a88267b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Asset/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ class ReCaptcha extends JavaScript
/** @var string */
protected $renderType;

/** @var string */
protected $theme;

/**
* {@inheritdoc}
*/
public function __toString()
{
$onLoad = ($this->getRenderType() == 'invisible') ? '&render=explicit&onload=invisibleRecaptchaOnLoad' : '';
$theme = sprintf('<script>var RecaptchaOptions = { theme : "" };</script>', 'clean');
$theme = sprintf('<script>var RecaptchaOptions = { theme : "%s" };</script>', $this->getTheme());
$api = sprintf('<script src="https://www.google.com/recaptcha/api.js?hl=%s%s" async defer></script>', $this->getHtmlLang(), $onLoad);

return $theme . $api;
Expand Down Expand Up @@ -86,4 +89,23 @@ public function setRenderType($type)

return $this;
}

/**
* @return string
*/
public function getTheme()
{
return $this->theme;
}

/**
* @param string $theme
* @return ReCaptcha
*/
public function setTheme($theme)
{
$this->theme = $theme;

return $this;
}
}
1 change: 1 addition & 0 deletions src/BoltForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ private function queueReCaptcha()
$reCaptcha
->setHtmlLang($this->app['locale'])
->setRenderType($this->config->getReCaptcha()->get('type'))
->setTheme($this->config->getReCaptcha()->get('theme'))
->setLocation(Target::END_OF_BODY)
->setZone(Zone::FRONTEND)
;
Expand Down

0 comments on commit a88267b

Please sign in to comment.