? addresses-topcountries.patch
Index: addresses.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/addresses/addresses.inc,v
retrieving revision 1.62
diff -u -p -r1.62 addresses.inc
--- addresses.inc	29 Jan 2010 15:27:36 -0000	1.62
+++ addresses.inc	8 Jun 2010 20:14:56 -0000
@@ -25,7 +25,7 @@
  *   Array. 'COUNTRY CODE' => 'COUNTRY NAME' pairs as layed out in
  *   ISO 3166-1 alpha-2
  */
-function _addresses_country_get($available = array(), $upper = FALSE) {
+function _addresses_country_get($available = array(), $top = array(), $upper = FALSE) {
   $countries = array(
     'ad' => t('Andorra'),
     'ae' => t('United Arab Emirates'),
@@ -282,16 +282,27 @@ function _addresses_country_get($availab
     }
   }
 
+  // Sort the list and return
+  natcasesort($countries);
+
+  // Move any designated countries to the top of the list
+  if (!empty($top)) {
+    $top_countries = array();
+    foreach ($countries as $ccode => $country) {
+      if (!empty($top[$ccode])) {
+        $top_countries[$ccode] = $countries[$ccode];
+        unset($countries[$ccode]);
+      }
+    }
+    $countries = array_merge($top_countries, $countries);
+  }
+
   // In fact, the ISO codes for countries are all Upper Case.
   // So, if someone needs the list as the official records,
   // it will convert.
   if (!empty($upper)) {
     $countries = array_change_key_case($countries, CASE_UPPER);
   }
-
-  // Sort the list and return
-  natcasesort($countries);
-
   return $countries;
 }
 
Index: addresses.settings.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/addresses/addresses.settings.inc,v
retrieving revision 1.38
diff -u -p -r1.38 addresses.settings.inc
--- addresses.settings.inc	28 May 2010 03:36:48 -0000	1.38
+++ addresses.settings.inc	8 Jun 2010 20:14:56 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: addresses.settings.inc,v 1.38 2010/05/28 03:36:48 codycraven Exp $
+// $Id: addresses.settings.inc,v 1.37 2010/02/09 23:18:40 codycraven Exp $
 /**
  * @author Bruno Massa
  * @file
@@ -43,7 +43,7 @@ function _addresses_addressesfieldapi_fo
   // Adds the Country
   if (!empty($fields['country'])) {
     // Get a list of enabled countries
-    $countries = _addresses_country_get(variable_get('addresses_country_list', array()));
+    $countries = _addresses_country_get(variable_get('addresses_country_list', array()), variable_get('addresses_country_top', array()));
     if (count($countries) > 1) {
       $countries = array('' => '') + $countries;
     }
@@ -408,6 +408,7 @@ function _addresses_settings(&$form_stat
   module_load_include('inc', 'addresses');
   $countries = _addresses_country_get();
   $country_list = variable_get('addresses_country_list', array_keys(_addresses_country_get()));
+  $top_countries = variable_get('addresses_country_top', array());
 
   // List of countries that the site allow
   $form['addresses_country_list'] = array(
@@ -419,6 +420,15 @@ function _addresses_settings(&$form_stat
     '#title' => t('Possible country'),
   );
 
+  $form['addresses_country_top'] = array(
+    '#default_value' => $top_countries,
+    '#description' => t('Select any countries you want to move to the top of the list.'),
+    '#multiple' => TRUE,
+    '#options' => $countries,
+    '#type' => 'select',
+    '#title' => t('Top countries'),
+  );
+
   // Allow users to change address formats
   $countries = array_intersect_key($countries, $country_list);
   array_unshift($countries, t('Default'));
