Download & Extend

Give administrators the ability to limit country options

Project:Location
Version:6.x-3.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

Is there a way of choosing which countries to display? I would like to have only a predefined set of countries to be displayed everywhere including Views filters. Currently it shows all the countries which is in my case too much.

Thanks!
Javier

Comments

#1

i would like to know how to do this too =)

#2

+1 needing to know how to do this. I can't figure it out either.

#3

I would like to limit countries to only those which are part of the dataset the view represents. Say we have 100 nodes to search from, and they are hotels in 30 counties, and i want to expose the Location (Country/City). can we limit the country's in the exposed filter dropdown only to the 30 in the dataset, instead of all of them??

thanks,
m

#4

In the function location_get_iso3166_list in location.inc is the list of countries.

You can comment out the ones you don't want. Just put // at the start of the lines with the countries you don't want in the list.

#5

Title:How to limit the countries displayed in the dropdown» Give administrators the ability to limit country options
Version:6.x-3.1-rc1» 6.x-3.x-dev
Component:Miscellaneous» Code
Category:support request» feature request

Changing this to a feature request.

Administrators should be able to select, from the list of all countries, which countries will be options in the country field.

#6

Thank you, this helped.

#7

#8

These are great tweaks/fixes but they don't solve for this case:

What if we want to allow admins to post both international and US locations using the drop down (for country), but only allow our site visitors to search via an exposed location country drop down that only shows the international locations (but not the US). I have 2 exposed block Views - one for searching US state and one for searching International. So on the international one I want all the countries to show up except for United States.

Can we just remove one of the countries from the exposed View?

-backdrifting

#9

@backdrifting hook_form_alter will save your day

#10

Ok, cool. I'd stick the form_alter in the Views module correct? Or would I add it to location?

I only want to alter the output of the exposed drop down form in the view.

-backdrifting

#11

Will hook_form_alter work even though it's a drop down select list?

<select name="country" class="form-select location_auto_country location_auto_join_country" id="edit-country" >

-backdrifting

#12

Ok I've added the following to my template.php file in the theme folder but I can't get the print_r to work:

/**
* Implements HOOK_theme().
*/
function themename_theme(&$existing, $type, $theme, $path) {
  return array(
    // The form ID.
    'views_exposed_form_find_sales_rep_international_block_1_form' => array(
      // Forms always take the form argument.
      'arguments' => array('form' => NULL),
    ),
  );
}

and this is the function to print_r:

/**
   * Theme override for views exposed country drop down list
   */
  function themename_views_exposed_form_find_sales_rep_international_block_1_form($form) {
    return print_r($form);
  }

What am I doing wrong here? I'm pretty sure this is the name of the View block form - I got this from the form id in view source.

-backdrifting

#13

Here is an example with hook_form_alter for exposed filter

<?php
function hook_form_alter(&$form, $form_state, $form_id) {
 
 
// remove all countries except for be and nl from location module
 
if (isset($form['country'])) {
    foreach (
$form['country']['#options'] as $key => $value) {
      if (
$key != 'be' && $key != 'nl' && $key != 'All') {
        unset(
$form['country']['#options'][$key]);
      }
    }
  }

}
?>

#14

Ok, I'll try this. So this should go in the views.module file? Or should I create a custom module file for it?

-backdrifting

#15

The problem is - is this going to override and make tweaks to the country location form used in the location module as part of the create content form? I just want to remove a country from the exposed view filter but not from the location module country select list.

-backdrifting

#16

Add it in a custom module 'yoursite'.module and no, it will only affect your exposed views. Just give it a try.

#17

Cool. Ok, I'll try it. Thanks so much.

-backdrifting

#18

Hmmm ... I've uploaded the module and tried this but it's not affecting the exposed filter. All countries are still showing.

-backdrifting

#19

Subscribing. It would be great to have an easy way to do this.

#20

+1
tried the function in a custom module but countries are still showing. maybe I need to flush some caches (although I am in theme devel mode and no caching)

selecting the available countries on Location CCK would be a good improvement. I guess this hack will limit the countries in ALL Location select inputs? I just need it in a single node field.

IMHO Location CCK is powerful but still not flexible enough. In my wish-list: select list for provinces and auto-fill with zip code entered, out of the box.

#21

Status:active» needs review

In my opinion, abillity to limit countries is very usefull and sometimes neccessary. I am attaching the patch with my own proposal.

AttachmentSize
screenshot_admin_settings_552894_p1.png 6.75 KB
screenshot_countries_list_552894_p1.png 62.81 KB
552894-location-p1-D6.patch 3.49 KB

#22

Tested the patch in #21. I was able to enter my chosen countries in the Admin interface however, I was unable to view ONLY those countries. It's still showing everything in both the Views Proximity Filter list and on the resulting View.

#23

Status:needs review» needs work

Indeed, #21 wasn't designed to work with views.

#24

Subscribing: Would like to limit countries to those available in the existing nodes. So if there are no nodes "located" in Japan, Japan will not be in the location: country filter but as soon as I create a node that is "located" in Japan, it (Japan) will become available in the filter.

#25

subscribing - I would like to just show US and Canada in the country list for Content Profile.

#26

I know this doesn't give admins the ability to easily change the list of available countries...but it is a way to achieve it easily. With very little headache I implemented this on one of my sites.

http://drupal.stackexchange.com/questions/4559/how-to-alter-country-drop...

#27

Hey, thanks for sharing that link.

The article shows how you can create a simple module that populates the drop down menu that you specify with a tailor made list. It's actually pretty neat but it would be even more useful if it were extended to loop through the database and populate the drop-down with only countries that are relevant to the content in question.

I don't (think I) have the time right now to explore that at the moment but I think it could work and I'll investigate a little more as soon as I can free up some time.

Andrew

#28

subscribing

nobody click here