You are here

public function TaxNumberItem::getAllowedCountries in Commerce Core 8.2

Gets the allowed countries.

Tax numbers will be collected only for these countries.

Return value

string[] A list of country codes.

Overrides TaxNumberItemInterface::getAllowedCountries

File

modules/tax/src/Plugin/Field/FieldType/TaxNumberItem.php, line 269

Class

TaxNumberItem
Plugin implementation of the 'commerce_tax_number' field type.

Namespace

Drupal\commerce_tax\Plugin\Field\FieldType

Code

public function getAllowedCountries() {
  $countries = array_filter($this
    ->getSetting('countries'));
  if (in_array('EU', $countries)) {

    // Replace the EU country with actual members of the EU, plus IM and MC.
    // Same list as in the european_union_vat tax number plugin.
    $eu_countries = [
      'AT',
      'BE',
      'BG',
      'CY',
      'CZ',
      'DE',
      'DK',
      'EE',
      'ES',
      'FI',
      'FR',
      'GR',
      'HR',
      'HU',
      'IE',
      'IM',
      'IT',
      'LT',
      'LU',
      'LV',
      'MC',
      'MT',
      'NL',
      'PL',
      'PT',
      'RO',
      'SE',
      'SI',
      'SK',
    ];
    $countries = array_diff($countries, [
      'EU',
    ]);
    $countries = array_merge($countries, $eu_countries);
  }
  if (empty($countries)) {

    // All countries are allowed.
    $country_list = \Drupal::service('address.country_repository')
      ->getList();
    $countries = array_keys($country_list);
  }
  return $countries;
}