Skip to content

Commit

Permalink
Merge branch 'fix-recaptcha' of git://github.com/Matteo-Peronnet/Widg…
Browse files Browse the repository at this point in the history
…etFormBundle into Matteo-Peronnet-fix-recaptcha
  • Loading branch information
paulandrieux committed Apr 30, 2018
2 parents 3b22a63 + 43fe287 commit d2eacb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
5 changes: 2 additions & 3 deletions Resources/config/assetic_injector.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"javascripts":
{
"foot": [
"@VictoireWidgetFormBundle/Resources/public/js/validator.js",
"https://www.google.com/recaptcha/api.js"
"@VictoireWidgetFormBundle/Resources/public/js/validator.js"
]
},
"stylesheets":
{
"head": "@VictoireWidgetFormBundle/Resources/public/css/recaptcha.css"
"victoire_widget_form_recaptcha": "@VictoireWidgetFormBundle/Resources/public/css/recaptcha.css"
}
}
}
14 changes: 1 addition & 13 deletions Resources/views/macros/form_elements.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
{% macro recaptcha(siteKey)%}

{% stylesheets injector="head"
'@VictoireWidgetFormBundle/Resources/public/css/recaptcha.css'
%}
{% endstylesheets %}

<div class="g-recaptcha" data-sitekey="{{siteKey}}"></div>

{% javascripts injector="foot"
'http://www.google.com/recaptcha/api.js'
%}
{% endjavascripts %}

{% endmacro %}
{% endmacro %}
15 changes: 15 additions & 0 deletions Resources/views/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,24 @@
</div>

{% if recaptcha_public_key is defined %}
{% stylesheets injector="victoire_widget_form_recaptcha"
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
<div class="row">
<div class="col-xs-12">
{{formElements.recaptcha(recaptcha_public_key)}}
<script type="text/javascript">
(function() {
if (!document.getElementById('google_recaptcha_script_tag')) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'google_recaptcha_script_tag';
script.src = 'https://www.google.com/recaptcha/api.js?explicit&hl={{ app.request.locale }}';
document.getElementsByTagName('body')[0].appendChild(script);
}
})();
</script>
</div>
</div>
{% endif %}
Expand Down

0 comments on commit d2eacb3

Please sign in to comment.