Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#1 | cck_country_countries_sort_order.patch | 441 bytes | tlaurent |
Comments
Comment #1
tlaurent CreditAttribution: tlaurent commentedI 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).
Comment #2
Scyther CreditAttribution: Scyther commentedI 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.
Comment #3
Scyther CreditAttribution: Scyther commentedComment #4
Scyther CreditAttribution: Scyther commentedCountry 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.
Comment #5
Scyther CreditAttribution: Scyther commented