function _location_country_select_options in Location 5
Given a pre-selected value, whether or not the form-item is required, and an optional form name, generates an HTML select for selecting a country in an location form.
Parameters
$value: A pre-selected value for this field.
$required: A boolean for whether this field is required or not.
$form_name: The HTML "name" attribute assigned to the generated form element. Defaults to 'location' if none is specified
Return value
A form_select where the labels are the English names of the countries and the corresponding value attributes for the options are the two-letter ISO code for the countries. If 'location' is passed as the $form_name, then the HTML "name" attribute for the generated form element will be "edit[location][country]".
1 call to _location_country_select_options()
- location_form in ./
location.inc - Generates a Drupal HTML form for collecting locationes.
File
- ./
location.inc, line 1186
Code
function _location_country_select_options($value = '', $required = FALSE, $function = NULL) {
if ($function) {
$function = $function == 'nearby_postalcodes_bylocation' || $function == 'nearby_postalcodes_bylatlon' ? 'latlon_rough' : $function;
$countrycodes = array();
foreach (location_configured_countries() as $code => $full_name) {
if (function_exists('location_' . $function . '_' . $code)) {
$countrycodes[$code] = $full_name;
}
}
$countrycodes = array_merge(array(
'' => '',
), $countrycodes);
}
else {
$countrycodes = array_merge(array(
'' => '',
'xx' => 'NOT LISTED',
), _location_get_iso3166_list());
}
return array(
'#type' => 'select',
'#title' => t('Country'),
'#default_value' => $value,
'#options' => $countrycodes,
'#description' => NULL,
'#extra' => 0,
'#multiple' => FALSE,
'#required' => $required,
);
}