With countries_filter() it already is possible to filter countries returned by countries_get_countries() in some different ways. But this only works if you are calling it yourself. If another module want to get countries, e. g. addressfield, you cannot provide a filter this way. To be able to filter the countries there as well, you need an alter hook.

Comments

mvonfrie’s picture

I added the hook as well as a hook to alter the filter before it is executed. This is to prevent conflicting logic between filtering and altering the countries list (if you unset all filters the alter hook gets the unflitered countries list.)