You are here

function phone_countries in Phone 7.2

Same name and namespace in other branches
  1. 7 phone.module \phone_countries()

Helper function to get a list of countries.

Parameters

mixed $codes: One or more codes to actually lookup.

string $type: When this is 'country', returns the country name. When this is 'calling_code', returns the calling code. When this is 'combined', returns a combined country name with the calling code for countries we have a calling code for. Defaults to 'combined'.

bool $reset: When TRUE, resets any cached data. Defaults to FALSE.

Return value

array When $codes is empty, an array of all countries is returned. When $codes is an array, only countries matching those codes are returned. When $codes is a string, and exists in the detected countries, returns the country name. Otherwise returns FALSE.

8 calls to phone_countries()
phone_element_process in includes/phone.element.inc
Process an individual phone element.
phone_feeds_set_target in ./phone.feeds.inc
Callback for mapping. Here is where the actual mapping happens.
phone_field_formatter_view in ./phone.module
Implements hook_field_formatter_view().
phone_field_instance_settings_form in ./phone.module
Implements hook_field_instance_settings_form().
phone_field_property_country_options in ./phone.module
Callback for getting the possible list of country codes for entity metadata.

... See full list

File

./phone.module, line 135
The phone module lets administrators use a phone number field type.

Code

function phone_countries($codes = NULL, $type = 'combined', $reset = FALSE) {

  // We don't need drupal_static() do we? Why would we reset this?
  static $country_data = NULL;
  if (!isset($country_data) || $reset) {
    if (!$reset && ($cache = cache_get('phone_countries'))) {
      $country_data = $cache->data;
    }
    if (!isset($country_data)) {

      // Load libphonenumber.
      phone_libphonenumber();
      $country_data = phone_libphonenumber_get_supported_country_lists();
      cache_set('phone_countries', $country_data);
    }
  }
  if (empty($codes)) {
    return $country_data[$type];
  }
  elseif (is_array($codes)) {
    return array_intersect_key($country_data[$type], drupal_map_assoc($codes));
  }
  elseif (isset($country_data[$type][$codes])) {
    return $country_data[$type][$codes];
  }
  else {
    return FALSE;
  }
}