public function UcAddressesUcCountryFieldHandler::getFormField in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 handlers/ubercart.handlers.inc \UcAddressesUcCountryFieldHandler::getFormField()
Implements UcAddressesFieldHandler::getFormField().
Overrides UcAddressesFieldHandler::getFormField
File
- handlers/
ubercart.handlers.inc, line 190 - Field handlers for Ubercart core address fields: first_name, last_name, company, etc.
Class
- UcAddressesUcCountryFieldHandler
- Class for the Ubercart country field.
Code
public function getFormField($form, $form_values) {
$fieldName = $this
->getFieldName();
$fieldValue = $this
->getAddress()
->getField($fieldName);
$default = isset($form_values[$fieldName]) ? $form_values[$fieldName] : $fieldValue;
$result = db_query("SELECT * FROM {uc_countries} WHERE version > 0 ORDER BY country_name");
$countries = array();
while ($country = db_fetch_object($result)) {
// Create option.
$countries[$country->country_id] = t($country->country_name);
// Save for later use.
self::$countries[$country->country_id] = $country;
}
if (count($countries) == 0) {
$countries[] = t('No countries found.');
}
else {
// Sort countries list in natural order.
natcasesort($countries);
}
drupal_add_js(drupal_get_path('module', 'uc_store') . '/uc_country_select.js');
// Ensure the path setting only gets added once.
static $added = FALSE;
if (!$added) {
drupal_add_js(array(
'ucURL' => array(
'zoneSelect' => url('uc_js_util/zone_select'),
),
), 'setting');
$added = TRUE;
}
return array(
$fieldName => array(
'#type' => 'select',
'#title' => $this
->getFieldTitle(),
'#options' => $countries,
'#required' => $this
->isFieldRequired(),
'#default_value' => empty($default) ? uc_store_default_country() : $default,
),
);
}