Looking for some advice. My Drupal background is quite limited, but I'll do my best to use the correct terminology.
Basically we have a view that is used to search for organizations based on the country. So when I go to the view for the search page and click on the configure filter criterion, I see a series of check boxes associated with the field_address:county field that is a long list of countries.
The values for the countries appears to come from the file: includes/iso.inc
What I'm trying to do is change some of the names, plus add one or two countries. The reason for this is this search is based on where our organization works. For example we have a separate organization in Northern Ireland. Of course this is not listed in the ISO.inc file.
I was not able to figure out how the ISO.inc values are tied to the field_address_country, but they are.
My first instinct was to, heck, just modify the ISO.inc file. But then I was told that was bad because that is like hacking core.
After some Google searching I found I could add to a function Hook to an existing custom module that deals with forms (written by 3rd party) with a hook for countries alter.
function myCustomMod_countries_alter(&$countries) {
$countries['IE'] = 'Republic of Ireland-xx'; $countries['GB'] = 'Great Britain'; $countries['RU'] = 'Russian Federation'; $countries['CI'] = 'Cote d' lvoire'; $countries['BA'] = 'Bosnia Herzegovina'; $countries['NN'] = 'Northern Ireland';
}
Now when I go to the view, this has no effect on the list of countries, but when I go to the search page that uses this view with exposed criteria and form, I can see that the countries that exist in the iso file (e.g. Republic of Ireland with an -xx) are modified with my changes from the countries_alter hook, but the countries that do not exist in the iso file are not added (e.g. Northern Ireland). I am guessing at the time the exposed search drop down list is built, it has my changes in it (altered and added) but that it checks against the values that are checked in the view and if it's not check in the view, it won't get added to the list.
So looking for advice as to what direction I should head.
1.) Hack the ISO.inc file. 2.) learn how to attach another .inc file to the field_address:country 3.) another hook or code in the hook alter that will work when the form is rendered.
Pat.
On Mon, Oct 8, 2012 at 3:45 PM, Pat Newberry wrote:
After some Google searching I found I could add to a function Hook to an existing custom module that deals with forms (written by 3rd party) with a hook for countries alter.
function myCustomMod_countries_alter(&$countries) {
$countries['IE'] = 'Republic of Ireland-xx'; $countries['GB'] = 'Great Britain'; $countries['RU'] = 'Russian Federation'; $countries['CI'] = 'Cote d' lvoire'; $countries['BA'] = 'Bosnia Herzegovina'; $countries['NN'] = 'Northern Ireland';
}
Now when I go to the view, this has no effect on the list of countries, but when I go to the search page that uses this view with exposed criteria and form, I can see that the countries that exist in the iso file (e.g. Republic of Ireland with an -xx) are modified with my changes from the countries_alter hook, but the countries that do not exist in the iso file are not added (e.g. Northern Ireland). I am guessing at the time the exposed search drop down list is built, it has my changes in it (altered and added) but that it checks against the values that are checked in the view and if it's not check in the view, it won't get added to the list.
Have you cleared the caches? admin/config/development/performance
So looking for advice as to what direction I should head.
1.) Hack the ISO.inc file. 2.) learn how to attach another .inc file to the field_address:country 3.) another hook or code in the hook alter that will work when the form is rendered.
Perhaps another hook. Have you looked at drupal.org/project/location? Do you know about api.drupal.org?
On 10/8/2012 5:21 PM, Earnie Boyd wrote:
On Mon, Oct 8, 2012 at 3:45 PM, Pat Newberry wrote:
After some Google searching I found I could add to a function Hook to an existing custom module that deals with forms (written by 3rd party) with a hook for countries alter.
function myCustomMod_countries_alter(&$countries) {
$countries['IE'] = 'Republic of Ireland-xx'; $countries['GB'] = 'Great Britain'; $countries['RU'] = 'Russian Federation'; $countries['CI'] = 'Cote d' lvoire'; $countries['BA'] = 'Bosnia Herzegovina'; $countries['NN'] = 'Northern Ireland';
}
Now when I go to the view, this has no effect on the list of countries, but when I go to the search page that uses this view with exposed criteria and form, I can see that the countries that exist in the iso file (e.g. Republic of Ireland with an -xx) are modified with my changes from the countries_alter hook, but the countries that do not exist in the iso file are not added (e.g. Northern Ireland). I am guessing at the time the exposed search drop down list is built, it has my changes in it (altered and added) but that it checks against the values that are checked in the view and if it's not check in the view, it won't get added to the list.
Have you cleared the caches? admin/config/development/performance
So looking for advice as to what direction I should head.
1.) Hack the ISO.inc file. 2.) learn how to attach another .inc file to the field_address:country 3.) another hook or code in the hook alter that will work when the form is rendered.
Perhaps another hook. Have you looked at drupal.org/project/location? Do you know about api.drupal.org?
I have cleared caches, I can tell that because my changes to the existing countries takes affect in the drop down list on the search page.
I'll check out another hook. I initially tried and that is where I came up with the countries_alter hook as shown above. I'll do a second pass and see if another seems like it might fit.
Pat
On Mon, Oct 8, 2012 at 5:25 PM, Pat Newberry wrote:
On 10/8/2012 5:21 PM, Earnie Boyd wrote:
On Mon, Oct 8, 2012 at 3:45 PM, Pat Newberry wrote:
After some Google searching I found I could add to a function Hook to an existing custom module that deals with forms (written by 3rd party) with a hook for countries alter.
function myCustomMod_countries_alter(&$countries) {
$countries['IE'] = 'Republic of Ireland-xx'; $countries['GB'] = 'Great Britain'; $countries['RU'] = 'Russian Federation'; $countries['CI'] = 'Cote d' lvoire'; $countries['BA'] = 'Bosnia Herzegovina'; $countries['NN'] = 'Northern Ireland';
}
Now when I go to the view, this has no effect on the list of countries, but when I go to the search page that uses this view with exposed criteria and form, I can see that the countries that exist in the iso file (e.g. Republic of Ireland with an -xx) are modified with my changes from the countries_alter hook, but the countries that do not exist in the iso file are not added (e.g. Northern Ireland). I am guessing at the time the exposed search drop down list is built, it has my changes in it (altered and added) but that it checks against the values that are checked in the view and if it's not check in the view, it won't get added to the list.
Have you cleared the caches? admin/config/development/performance
So looking for advice as to what direction I should head.
1.) Hack the ISO.inc file. 2.) learn how to attach another .inc file to the field_address:country 3.) another hook or code in the hook alter that will work when the form is rendered.
Perhaps another hook. Have you looked at drupal.org/project/location? Do you know about api.drupal.org?
I have cleared caches, I can tell that because my changes to the existing countries takes affect in the drop down list on the search page.
I'll check out another hook. I initially tried and that is where I came up with the countries_alter hook as shown above. I'll do a second pass and see if another seems like it might fit.
You may want to check the views specific hooks. http://api.drupal.org/api/views
On 10/8/2012 5:21 PM, Earnie Boyd wrote:
On Mon, Oct 8, 2012 at 3:45 PM, Pat Newberry wrote:
After some Google searching I found I could add to a function Hook to an existing custom module that deals with forms (written by 3rd party) with a hook for countries alter.
function myCustomMod_countries_alter(&$countries) {
$countries['IE'] = 'Republic of Ireland-xx'; $countries['GB'] = 'Great Britain'; $countries['RU'] = 'Russian Federation'; $countries['CI'] = 'Cote d' lvoire'; $countries['BA'] = 'Bosnia Herzegovina'; $countries['NN'] = 'Northern Ireland';
}
Now when I go to the view, this has no effect on the list of countries, but when I go to the search page that uses this view with exposed criteria and form, I can see that the countries that exist in the iso file (e.g. Republic of Ireland with an -xx) are modified with my changes from the countries_alter hook, but the countries that do not exist in the iso file are not added (e.g. Northern Ireland). I am guessing at the time the exposed search drop down list is built, it has my changes in it (altered and added) but that it checks against the values that are checked in the view and if it's not check in the view, it won't get added to the list.
Have you cleared the caches? admin/config/development/performance
So looking for advice as to what direction I should head.
1.) Hack the ISO.inc file. 2.) learn how to attach another .inc file to the field_address:country 3.) another hook or code in the hook alter that will work when the form is rendered.
Perhaps another hook. Have you looked at drupal.org/project/location? Do you know about api.drupal.org?
Using the information in this link (http://drupal.stackexchange.com/questions/4559/how-to-alter-country-dropdown...) I was able to accomplish what I needed done. I had an existing custom module in which I added this code:
/** * Implements hook_form_alter(). */ function MyModule_form_alter(&$form, &$form_state, $form_id) { if ($form['#id'] == 'views-exposed-form-listing-search-page') { $form['#after_build'][] = 'custom_countries_after_build'; } }
/** * Make changes to countries field after all fields are rendered */ function custom_countries_after_build($form_element, &$form_state) { $form_element['country']['#options']['NN'] = 'Northern Ireland'; $form_element['country']['#options']['IE'] = 'Republic of Ireland'; $form_element['country']['#options']['GB'] = 'Great Britain'; $form_element['country']['#options']['RU'] = 'Russian Federation'; $form_element['country']['#options']['CI'] = 'Cote d' lvoire'; $form_element['country']['#options']['BA'] = 'Bosnia Herzegovina'; $form_element['country']['#options']['CD'] = 'Democratic Republic of Congo';
asort($form_element['country']['#options']);
return $form_element; }