You are here

public function Validator::getCountryList in Telephone Validation 8.2

Get list of countries with country code and leading digits.

Return value

array Flatten array you can use it directly in select lists.

File

src/Validator.php, line 87

Class

Validator
Performs telephone validation.

Namespace

Drupal\telephone_validation

Code

public function getCountryList() {
  $regions = [];
  foreach ($this->countryManager
    ->getList() as $region => $name) {
    $region_meta = $this->phoneUtils
      ->getMetadataForRegion($region);
    if (is_object($region_meta)) {
      $regions[$region] = (string) new FormattableMarkup('@country - +@country_code', [
        '@country' => $name,
        '@country_code' => $region_meta
          ->getCountryCode(),
      ]);
    }
  }
  return $regions;
}