Commit c3e689b8 authored by Tino Goratsch's avatar Tino Goratsch

minor code refactoring

parent 5ceabe17
......@@ -7,6 +7,7 @@
namespace ACP3\Modules\ACP3\Captcha\Event\Listener;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Core\View;
use ACP3\Modules\ACP3\Captcha\Installer\Schema;
......@@ -26,18 +27,28 @@ class RenderRecaptchaOnLayoutContentBeforeListener
* @var UserModel
*/
private $userModel;
/**
* @var Translator
*/
private $translator;
/**
* RenderRecaptchaOnLayoutContentBeforeListener constructor.
* @param Translator $translator
* @param SettingsInterface $settings
* @param View $view
* @param UserModel $userModel
*/
public function __construct(SettingsInterface $settings, View $view, UserModel $userModel)
public function __construct(
Translator $translator,
SettingsInterface $settings,
View $view,
UserModel $userModel)
{
$this->settings = $settings;
$this->view = $view;
$this->userModel = $userModel;
$this->translator = $translator;
}
public function renderRecaptcha()
......@@ -46,7 +57,8 @@ class RenderRecaptchaOnLayoutContentBeforeListener
if ($this->isRecaptcha($settings)) {
$this->view->assign('recaptcha', [
'sitekey' => $settings['recaptcha_sitekey']
'sitekey' => $settings['recaptcha_sitekey'],
'lang' => $this->translator->getShortIsoCode()
]);
$this->view->displayTemplate('Captcha/Partials/captcha_recaptcha.onload.tpl');
}
......
......@@ -78,13 +78,9 @@ class ReCaptchaCaptchaExtension implements CaptchaExtensionInterface
$path = ''
) {
if (!$this->user->isAuthenticated()) {
$settings = $this->settings->getSettings(Schema::MODULE_NAME);
$this->view->assign('captcha', [
'id' => $formFieldId,
'input_only' => $inputOnly,
'sitekey' => $settings['recaptcha_sitekey'],
'language' => $this->translator->getShortIsoCode()
'input_only' => $inputOnly
]);
return $this->view->fetchTemplate('Captcha/Partials/captcha_recaptcha.tpl');
......
......@@ -9,7 +9,7 @@
};
</script>
<script type="text/javascript"
src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&amp;render=explicit"
src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&amp;render=explicit&amp;hl={$recaptcha.lang}"
async
defer></script>
{/javascripts}
......@@ -9,5 +9,5 @@
{block FORM_GROUP_LABEL_ID}for="{$captcha.id}"{/block}
{block FORM_GROUP_FORM_FIELD}
<div id="{$captcha.id}" class="recaptcha-placeholder" data-sitekey="{$captcha.sitekey}"></div>
<div id="{$captcha.id}" class="recaptcha-placeholder"></div>
{/block}
......@@ -17,6 +17,7 @@ services:
captcha.event.render_recaptcha_on_layout_content_before_listener:
class: ACP3\Modules\ACP3\Captcha\Event\Listener\RenderRecaptchaOnLayoutContentBeforeListener
arguments:
- '@core.lang'
- '@core.config'
- '@core.view'
- '@users.model.user_model'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment