You are here

function _telephone_validation_get_country_codes in Telephone Validation 7

Get list of all available countries with codes.

Return value

array Returns list of all countries from iso.inc file cross referenced with available country codes.

1 call to _telephone_validation_get_country_codes()
telephone_validation_form_field_ui_field_edit_form_alter in ./telephone_validation.module
Implements hook_form_FORM_ID_alter().

File

./telephone_validation.module, line 172
Validate phone number.

Code

function _telephone_validation_get_country_codes() {
  include_once DRUPAL_ROOT . '/includes/iso.inc';
  $phone_util = \libphonenumber\PhoneNumberUtil::getInstance();
  $regions = array();
  foreach (_country_get_predefined_list() as $region => $name) {
    $region_meta = $phone_util
      ->getMetadataForRegion($region);
    if (is_object($region_meta)) {
      $regions[$region] = $name . ' - +' . $region_meta
        ->getCountryCode() . ' ' . $region_meta
        ->getLeadingDigits();
    }
  }
  return $regions;
}