You are here

public static function MobileNumber::getCountryOptions in Mobile Number 7

Get all supported countries.

Parameters

array $filter: Limit options to the ones in the filter. (Eg. ['IL' => 'IL', 'US' => 'US'].

bool $show_country_names: Whether to show full country name instead of country codes.

Return value

array Array of options, with country code as keys. (Eg. ['IL' => 'IL (+972)'])

Overrides MobileNumberInterface::getCountryOptions

7 calls to MobileNumber::getCountryOptions()
MobileNumberClassTestCase::testFunctions in tests/mobile_number.class.test
Test functions.
mobile_number_element_process in ./mobile_number.module
Mobile number element process callback.
mobile_number_element_validate in ./mobile_number.module
Mobile number element validate callback.
mobile_number_field_widget_settings_form in ./mobile_number.module
Implements hook_field_widget_settings_form().
mobile_number_property_country_options in ./mobile_number.module
Helper function for get all supported countries for entity field country property.

... See full list

File

src/MobileNumber.php, line 151

Class

MobileNumber
Class MobileNumber handles mobile number validation and verification.

Code

public static function getCountryOptions($filter = array(), $show_country_names = FALSE) {
  $libUtil = PhoneNumberUtil::getInstance();
  $regions = $libUtil
    ->getSupportedRegions();
  $countries = array();
  foreach ($regions as $region => $country) {
    $code = $libUtil
      ->getCountryCodeForRegion($country);
    if (!$filter || !empty($filter[$country])) {
      $name = MobileNumber::getCountryName($country);
      $countries[$country] = $show_country_names && $name ? "{$name} (+{$code})" : "{$country} (+{$code})";
    }
  }
  asort($countries);
  return $countries;
}