countries_api_get_array() method return unsorted list of countries.

Please use for example asort() method.

Obviously it is possible to override the sorting using fapi but i think in this case it not worth adding more hooks
thanks

CommentFileSizeAuthor
#1 cck_country_countries_sort_order.patch441 bytestlaurent
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tlaurent’s picture

Status: Active » Needs review
FileSize
441 bytes

I ran into the same problem as well.
It's worth noting that this is only an issue if your Mysql database uses the InnoDB engine, as it stores data rows physically in pages in primary key order while MyISAM typically stores them mostly in the order in which they are added. So InnoDB will return the list of countries in the order of their iso2 (as it's the key) and not the order provided at install time by the [countries_api] module.
In fact, I think this issue should probably be sorted more elegantly in the [countries_api] module, by adding a sort option as parameter for the "countries_api_get_array()" function, but it might have an impact on other modules using [countries_api], so I'll let the maintainers to take care of this one.

In the meantime, if other people have the same problem, I've attached a very basic patch which will fix this issue (it only adds an asort to the "cck_country_allowed_values()" function, as n-tuple suggested).

Scyther’s picture

I think the sort should be handled by countries_api and in the SQL query and put the sort on the db instead of php. I am co-maintainer of countries_api module so I am working to see if it is possible to get it to sort.

Scyther’s picture

Status: Needs review » Active
Scyther’s picture

Status: Active » Fixed

Country codes API now sorts the list by printable_names, which is what CCK Country uses as display value in the select list. But this require that you uses the dev version of Country codes API until a 1.2 version or later is released.

See more here: #799664: Countries are not sorted in countries_api_get_list.

Scyther’s picture

Status: Fixed » Closed (fixed)