{% block component_captcha_friendly_captcha %}
{% set configNamespace = constant('Laudert\\FriendlyCaptcha\\LaudertFriendlyCaptcha::CONFIG_KEY') %}
{% set siteKey = config('%s.config.siteKey'|format(configNamespace)) %}
{% set secretKey = config('%s.config.secretKey'|format(configNamespace)) %}
{% if siteKey and secretKey %}
{% set locale = app.request.locale|slice(0, 2) %}
{% set supportedLanguages = [
'en', 'fr', 'de', 'it', 'nl', 'pt', 'es', 'ca', 'da',
'ja', 'el', 'uk', 'bg', 'cs', 'sk', 'no', 'fi', 'lt',
'pl', 'et', 'hr', 'sr', 'sl', 'hu', 'ro', 'nb', 'zh'
] %}
{% set friendlyCaptchaOptions = {
jsPluginOptions: {
deliveryMethod: config('%s.config.deliveryMethod'|format(configNamespace)),
polyfill: config('%s.config.polyfill'|format(configNamespace))
},
puzzleEndpoints: {
global: 'https://api.friendlycaptcha.com/api/v1/puzzle',
europe: 'https://eu-api.friendlycaptcha.eu/api/v1/puzzle'
},
lang: locale in supportedLanguages ? locale : 'en'
} %}
{% set puzzleEndpoint = friendlyCaptchaOptions.puzzleEndpoints.global %}
{% if config('%s.config.endpointSelection'|format(configNamespace)) == 'europe' %}
{% set puzzleEndpoint = friendlyCaptchaOptions.puzzleEndpoints.europe %}
{% if config('%s.config.endpointSelectionFallback'|format(configNamespace)) %}
{% set puzzleEndpoint = puzzleEndpoint ~ "," ~ friendlyCaptchaOptions.puzzleEndpoints.global %}
{% endif %}
{% endif %}
{% block component_friendly_captcha_form_row %}
<div class="form-row friendly-captcha">
{% block component_friendly_captcha_form_group %}
<div class="form-group {% if additionalClass %}{{ additionalClass }}{% else %}col-md-6{% endif %}">
{% block component_friendly_captcha_widget %}
{% set themeName = config('%s.config.theme.name'|format(configNamespace)) %}
<div
{# @see https://docs.friendlycaptcha.com/#/theme?id=dark-mode #}
class="frc-captcha{% if 'dark' === themeName %} dark{% endif %}"
{# this needs to be set with the html api or friendly captcha will issue a warning in the console. #}
data-sitekey="{{ siteKey }}" data-lang="{{ friendlyCaptchaOptions.lang }}"
data-friendly-captcha-plugin="true" data-start="{{ config('%s.config.startMode'|format(configNamespace)) }}"
data-puzzle-endpoint="{{ puzzleEndpoint }}"
data-friendly-captcha-plugin-options='{{ friendlyCaptchaOptions.jsPluginOptions|json_encode }}'
>
{# this div cannot be self closing because the form rows would break #}
</div>
{% endblock %}
<noscript>
{% sw_include '@Storefront/storefront/utilities/alert.html.twig' with {
type: 'warning',
heading: 'captcha.noscriptHeadline'|trans|sw_sanitize,
content: 'captcha.noscriptNotice'|trans|sw_sanitize
} %}
</noscript>
</div>
{% endblock %}
</div>
{% endblock %}
{% endif %}
{% endblock %}