custom/plugins/FourtwosixPhoneValidation/src/Resources/views/storefront/component/address/fts-telephone-country-prefixes.html.twig line 1

Open in your IDE?
  1. {% block fourtwosix_phone_prefix %}
  2.     {% if config("FourtwosixPhoneValidation.config.active") %}
  3.         {% set fourtwosixExtension = page.extension('FourtwosixPhoneNumberCountryPrefix') ?? null %}
  4.         {% set ftsPhonePrefix = fourtwosixExtension["fts_prefixes"] %}
  5.         {# 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 #}
  6.         {% set ftsAddressId = page.address.id ?? address.id %}
  7.         {% set uuid = ftsAddressId ?? random() %}
  8.         <div class="form-group col-md-2">
  9.             <p class="form-label"
  10.                for="{{ idPrefix ~ prefix }}AddressPhoneNumberPrefix-{{ ftsAddressId }}">
  11.                 {{ "fourwosixPhonePrefix.phoneNumberLabelPrefix"|trans|sw_sanitize }}
  12.                 {{ "general.required"|trans|sw_sanitize }}
  13.             </p>
  14.             <select
  15.                     {# added to the corresponding array billingAddress[] / shippinAddress[] / address #}
  16.                     name="{{ prefix }}[phonePrefix]"
  17.                     class="form-control prefix-from-iso"
  18.                     id="{{ idPrefix ~ prefix }}AddressPhoneNumberPrefix-{{ ftsAddressId }}"
  19.                     required="required"
  20.                     data-address-id="{{ uuid }}"
  21.             >
  22.                 <option
  23.                         {# ftsPhonePrefix has this structure [[id => value]] so if no id found and no extension set is a registration / new address creation #}
  24.                         {{ ftsPhonePrefix[ftsAddressId] ? "" : 'selected="true"' }}
  25.                         disabled="disabled"
  26.                         value>
  27.                     {{ "fourwosixPhonePrefix.chooseCountry"|trans|sw_sanitize }}
  28.                 </option>
  29.                 {% for ftsCountries in fourtwosixExtension["countries"] %}
  30.                     <option
  31.                             {# In /register /overview/address (modal) the form violation is presented as an associative array with
  32.                             [
  33.                                 'billingAddress/shippingAddress/address' => [
  34.                                 "phonePrefix" => "+49"
  35.                                 ]
  36.                             ]
  37.                             Therefore prepend the prefix to select the correct prefix in the dropdown
  38.                             ------------------------------------------------
  39.                             In address/{address-id} there is no associative array
  40.                             but is accessible directly
  41.                             [
  42.                                 "phonePrefix" => "+49"
  43.                             ] #}
  44.                             {% set formViolationPrefix = formViolations.inputData[idPrefix ~ prefix]["phonePrefix"] ?? formViolations.inputData["phonePrefix"] ?? false %}
  45.                             {% if formViolationPrefix === ftsCountries["prefix"] %}
  46.                                 selected="selected"
  47.                             {% else %}
  48.                                 {# Only if no violation are found we preload the data from the extension loaded via subscriber
  49.                                 this is for when the user makes a mistake eg. wrong zipcode but have also changed the prefix dropdown #}
  50.                                 {% if ftsPhonePrefix[ftsAddressId]  === ftsCountries["prefix"] %}
  51.                                     selected="selected"
  52.                                 {% endif %}
  53.                             {% endif %}
  54.                             data-iso="{{ ftsCountries["iso"] }}"
  55.                             value="{{ ftsCountries["prefix"] }}">
  56.                         {{ ftsCountries["prefix"] }} {{ ftsCountries["iso"] }}
  57.                     </option>
  58.                 {% endfor %}
  59.             </select>
  60.         </div>
  61.     {% endif %}
  62. {% endblock %}