{% sw_extends '@Storefront/storefront/component/address/address-form.html.twig' %}
{% block component_address_form_phone_number %}
{% if config('core.loginRegistration.showPhoneNumberField') and config('core.loginRegistration.showPhoneNumberField') %}
{% set fourtwosixExtension = page.extension('FourtwosixPhoneNumberCountryPrefix') ?? null %}
{% set ftsPhonePrefix = fourtwosixExtension["fts_prefixes"] %}
{# This can be address or page.address is passed as a parameter in vendor/shopware/storefront/Resources/views/storefront/component/address/address-editor-modal-create-address.html.twig #}
{% set ftsAddress = page.address ?? address %}
{% sw_include "@FourtwosixPhoneValidation/storefront/component/address/fts-telephone-country-prefixes.html.twig" with {
'fourtwosixExtension' : fourtwosixExtension,
'ftsPhonePrefix' : ftsPhonePrefix,
'ftsAddressId' : ftsAddress.id
} %}
{# @fourtwosix-edit: changed col-md-# #}
<div class="form-group col-md-{{ config("FourtwosixPhoneValidation.config.active") ? '4' : '6' }}">
{% if formViolations.getViolations("/phoneNumber") is not empty %}
{% set violationPath = "/phoneNumber" %}
{% elseif formViolations.getViolations("/#{prefix}/phoneNumber") is not empty %}
{% set violationPath = "/#{prefix}/phoneNumber" %}
{% endif %}
{% block component_address_form_phone_number_label %}
{{ parent() }}
{% endblock %}
{% set addressCustomFields = ftsAddress.customFields["fourtwosix_customer_address_prefix"] ?? null %}
{# Remove prefix. Note that to replace a variable it need to be passed within () otherwise wont work #}
{% if addressCustomFields %}
{% set getPhoneNumber = data.get('phoneNumber')|replace({(addressCustomFields) : ""}) %}
{% else %}
{% set getPhoneNumber = data.get('phoneNumber') %}
{% endif %}
{# TODO TO TEST ----------------#}
{% do data.setPhoneNumber(getPhoneNumber) %}
{% block component_address_form_phone_number_input %}
{{ parent() }}
{% endblock %}
{% block component_address_form_phone_error %}
{{ parent() }}
{% endblock %}
</div>
{% else %}
{{ parent() }}
{% endif %}
{% endblock %}