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.
By denix on
I would like to entirely replace the country list, but unfortunately I could not find any help in the hook_countries_alter(&$countries) documentation :(
I have a list of countries saved as "country" content type and I would like to use this list to override the iso.inc list but I have problems with multilingualism.
Any hint? Here is my code:
function country_countries_alter(&$countries){
$countries = array();
$query = db_select("node", "n")
->fields("n", array("nid"))
->condition("type", "country");
$results = $query->execute();
foreach ($results as $result) {
$node = node_load($result->nid);
$node_wrapper = entity_metadata_wrapper('node',$node);
$countries[$node_wrapper->field_country_iso2->value()] = t($node_wrapper->title->value());
};
}
What am I missing?
Thanks a lot!
Comments
What am I missing? A clear
A clear description of the problem. Actually, a description of the problem altogether, clear or otherwise.
Hi Jaypan, after posting the
Hi Jaypan,
after posting the question and going to sleep, I solved the problem.
The issue was that when I override the list of countries with my countries I was retrieving all the country names in all languages. I solved the issue adding a condition to the query. Here is the final code:
in case somebody else need to do the same thing.