function addressfield_tokens_states in Addressfield Tokens 7
Gets the list of states in the given country.
Parameters
string $country: The 2-letter abbreviation of the country.
Return value
array An array of countries. The keys are the 2-letter abbreviations and the values are the full country names.
1 call to addressfield_tokens_states()
- addressfield_tokens_state in ./
addressfield_tokens.module - Gets the name of the state with the given abbreviation.
File
- ./
addressfield_tokens.module, line 354 - Main components.
Code
function addressfield_tokens_states($country) {
global $language;
$langcode = $language->language;
$states =& drupal_static(__FUNCTION__);
$country = drupal_strtoupper($country);
if (!isset($states[$country])) {
$cache = cache_get('addressfield_tokens_states:' . $langcode);
if ($cache) {
$states = $cache->data;
}
}
if (!isset($states[$country])) {
$format = addressfield_generate(array(
'country' => $country,
), array(
'address',
), array(
'mode' => 'render',
));
if (isset($format['locality_block']['administrative_area']['#options'])) {
$states[$country] = $format['locality_block']['administrative_area']['#options'];
}
else {
$states[$country] = array();
}
cache_set('addressfield_tokens_states:' . $langcode, $states);
}
return $states[$country];
}