Hi,

first of all I have to do my compliments for the idea of this module: it will be very useful to many.

I'm playing now with this, using the Location module: what I would like to do is to obtain a global "country" dropdown filter, based on the "COUNTRY" provided by Location module.

My Global filter block is setted to use a custom view as source. This custom view is very similar to the "location_directory" view provided by default by Location module. This view simply retrieve all countries in the system that have at least a node associated to a country.

All works fine, the global filter does correctly his job on other views depending on this contextual global filter.

The issue is that the dropdown list shows country CODES (e.g. IT , US, AU) instead of country NAMES, despite in my custom view I've setted to show country names.

Is it a bug?

Thank you very much

MXT

(here's my exported view:)

$view = new view;
$view->name = 'global_filter';
$view->description = 'Questa view crea il global filter per filtrare la navigazione per Country';
$view->tag = 'default';
$view->base_table = 'location';
$view->human_name = 'Global filter';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 0;
/* Field: Location: Country */
$handler->display->display_options['fields']['country']['id'] = 'country';
$handler->display->display_options['fields']['country']['table'] = 'location';
$handler->display->display_options['fields']['country']['field'] = 'country';
$handler->display->display_options['fields']['country']['label'] = '';
$handler->display->display_options['fields']['country']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['country']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['country']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['country']['alter']['external'] = 0;
$handler->display->display_options['fields']['country']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['country']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['country']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['country']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['country']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['country']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['country']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['country']['alter']['trim'] = 0;
$handler->display->display_options['fields']['country']['alter']['html'] = 0;
$handler->display->display_options['fields']['country']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['country']['element_default_classes'] = 0;
$handler->display->display_options['fields']['country']['hide_empty'] = 0;
$handler->display->display_options['fields']['country']['empty_zero'] = 0;
$handler->display->display_options['fields']['country']['hide_alter_empty'] = 1;
CommentFileSizeAuthor
#5 global filter views results.jpg85.01 KBmxt

Comments

mxt’s picture

Any response on this?

thank you very much

rdeboer’s picture

Hi MTX,
Thank you for your report.

I've just been so busy that there hasn't been any time to address the issue queue for a while. Next week looks better.
Without having the code to look at, I'm wondering does changing the order of the views fields help?

Rik

mxt’s picture

Hi RdeBoer!

What do you mean with "changing the order of the views field" ? The view retrieves only one field: Location: Country field.

Here's the printed query from the view posted in the first post of this thread:

SELECT location.country AS location_country
FROM 
{location} location

I'm missing something?

Thank you!

rdeboer’s picture

Hi MXT,
What I mean is: your view needs to produce two result fields: the 2-letter country code and the full country name, and the country code may have to come first (unless it is internally marked by Views as the key id, in which case it doesn't matter).
Rik

mxt’s picture

StatusFileSize
new85.01 KB

Thank you RdeBoer,

following your advice, I've now added 2 fields. In truth, is always the same field Location: Country added 2 times in my views, but the first selecting CODE display in the fields settings, and the second selecting NAME (that's what a Location based view can offer):

$view = new view;
$view->name = 'global_filter';
$view->description = 'Questa view crea il global filter per filtrare la navigazione per Country';
$view->tag = 'default';
$view->base_table = 'location';
$view->human_name = 'Global filter';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 0;
/* Field: Location: Country CODE */
$handler->display->display_options['fields']['country']['id'] = 'country';
$handler->display->display_options['fields']['country']['table'] = 'location';
$handler->display->display_options['fields']['country']['field'] = 'country';
$handler->display->display_options['fields']['country']['ui_name'] = 'Location: Country CODE';
$handler->display->display_options['fields']['country']['label'] = '';
$handler->display->display_options['fields']['country']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['country']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['country']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['country']['alter']['external'] = 0;
$handler->display->display_options['fields']['country']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['country']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['country']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['country']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['country']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['country']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['country']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['country']['alter']['trim'] = 0;
$handler->display->display_options['fields']['country']['alter']['html'] = 0;
$handler->display->display_options['fields']['country']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['country']['element_default_classes'] = 0;
$handler->display->display_options['fields']['country']['hide_empty'] = 0;
$handler->display->display_options['fields']['country']['empty_zero'] = 0;
$handler->display->display_options['fields']['country']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['country']['style'] = 'code';
/* Field: Location: Country NAME */
$handler->display->display_options['fields']['country_1']['id'] = 'country_1';
$handler->display->display_options['fields']['country_1']['table'] = 'location';
$handler->display->display_options['fields']['country_1']['field'] = 'country';
$handler->display->display_options['fields']['country_1']['ui_name'] = 'Location: Country NAME';
$handler->display->display_options['fields']['country_1']['label'] = '';
$handler->display->display_options['fields']['country_1']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['external'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['country_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['country_1']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['country_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['country_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['country_1']['element_default_classes'] = 1;
$handler->display->display_options['fields']['country_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['country_1']['empty_zero'] = 0;
$handler->display->display_options['fields']['country_1']['hide_alter_empty'] = 1;

My view preview correctly shows the expected results (see image in attachment), but dropdown select provided by Views Global Filter always show ONLY country codes, here's the resulting HTML:

<div class="form-item form-type-select form-item-view-global-filter">
  <select id="edit-view-global-filter--2" class="global_filter_1-view_global_filter form-select" name="view_global_filter">
    <option selected="selected" value="">Worldwide</option>
    <option value="it">it</option>
    <option value="al">al</option>
  </select>
</div>

I don't know what to do, please help me!

Thank you

rdeboer’s picture

Hi MXT,

So I was finally able to set some time aside to get to the bottom of this.

The problem is that the Country NAME isn't actually in the Location table and so isn't in the View either (the View that is executed by Global Filter to populate the global country select list). Instead, for display purposes, the Country NAME is generated through code in the Location module, using the function location_country_name(..).

I tried to use the Views PHP module and created a Views field with the value location_country_name($row->country). This works.... however, it appears that the Views PHP field always comes last when Global Filter executes the View, even when the Views PHP field was rearranged to come first using the VIews UI.... Which means that Global Filter still picks up the country code rather than the country name....
Also the key field is lid (numeric) rather than the two-letter country code.

What I suggest is you create your own custom country field on an existing or dummy content type if necessary and then configure your Global Filter to drive of that.
You simply specify the countries as key|value pairs:

it|Italy
fr|France
..|...

etc.

Or you can define your countries as a taxonomy and then use that as a field or in a View which you then refer to in your Global Filter block. If you use a taxonomy you can introduce a hierarchy too, e.g. with the continent names (Europe, America, Asia...) as the parents and the countries as children. You can then use the "Select with Style" module to make it look nice.

rdeboer’s picture

Assigned: Unassigned » rdeboer
Category: bug » support
Status: Active » Fixed

Here's a list of country codes and names that you can use to create your own country field.

    ad|Andorra
    ae|United Arab Emirates
    af|Afghanistan
    ag|Antigua and Barbuda
    ai|Anguilla
    al|Albania
    am|Armenia
    an|Netherlands Antilles
    ao|Angola
    aq|Antarctica
    ar|Argentina
    as|American Samoa
    at|Austria
    au|Australia
    aw|Aruba
    ax|Aland Islands
    az|Azerbaijan
    ba|Bosnia and Herzegovina
    bb|Barbados
    bd|Bangladesh
    be|Belgium
    bf|Burkina Faso
    bg|Bulgaria
    bh|Bahrain
    bi|Burundi
    bj|Benin
    bm|Bermuda
    bn|Brunei
    bo|Bolivia
    br|Brazil
    bs|Bahamas
    bt|Bhutan
    bv|Bouvet Island
    bw|Botswana
    by|Belarus
    bz|Belize
    ca|Canada
    cc|Cocos (Keeling) Islands
    cd|Congo (Kinshasa)
    cf|Central African Republic
    cg|Congo (Brazzaville)
    ch|Switzerland
    ci|Ivory Coast
    ck|Cook Islands
    cl|Chile
    cm|Cameroon
    cn|China
    co|Colombia
    cr|Costa Rica
    cs|Serbia And Montenegro // Transitional reservation
    cu|Cuba
    cv|Cape Verde
    cx|Christmas Island
    cy|Cyprus
    cz|Czech Republic
    de|Germany
    dj|Djibouti
    dk|Denmark
    dm|Dominica
    do|Dominican Republic
    dz|Algeria
    ec|Ecuador
    ee|Estonia
    eg|Egypt
    eh|Western Sahara
    er|Eritrea
    es|Spain
    et|Ethiopia
    fi|Finland
    fj|Fiji
    fk|Falkland Islands
    fm|Micronesia
    fo|Faroe Islands
    fr|France
    ga|Gabon
    gd|Grenada
    ge|Georgia
    gf|French Guiana
    gg|Guernsey
    gh|Ghana
    gi|Gibraltar
    gl|Greenland
    gm|Gambia
    gn|Guinea
    gp|Guadeloupe
    gq|Equatorial Guinea
    gr|Greece
    gs|South Georgia and the South Sandwich Islands
    gt|Guatemala
    gu|Guam
    gw|Guinea-Bissau
    gy|Guyana
    hk|Hong Kong S.A.R., China
    hm|Heard Island and McDonald Islands
    hn|Honduras
    hr|Croatia
    ht|Haiti
    hu|Hungary
    id|Indonesia
    ie|Ireland
    il|Israel
    im|Isle of Man
    in|India
    io|British Indian Ocean Territory
    iq|Iraq
    ir|Iran
    is|Iceland
    it|Italy
    je|Jersey
    jm|Jamaica
    jo|Jordan
    jp|Japan
    ke|Kenya
    kg|Kyrgyzstan
    kh|Cambodia
    ki|Kiribati
    km|Comoros
    kn|Saint Kitts and Nevis
    kp|North Korea
    kr|South Korea
    kw|Kuwait
    ky|Cayman Islands
    kz|Kazakhstan
    la|Laos
    lb|Lebanon
    lc|Saint Lucia
    li|Liechtenstein
    lk|Sri Lanka
    lr|Liberia
    ls|Lesotho
    lt|Lithuania
    lu|Luxembourg
    lv|Latvia
    ly|Libya
    ma|Morocco
    mc|Monaco
    md|Moldova
    me|Montenegro
    mg|Madagascar
    mh|Marshall Islands
    mk|Macedonia
    ml|Mali
    mm|Myanmar
    mn|Mongolia
    mo|Macao S.A.R., China
    mp|Northern Mariana Islands
    mq|Martinique
    mr|Mauritania
    ms|Montserrat
    mt|Malta
    mu|Mauritius
    mv|Maldives
    mw|Malawi
    mx|Mexico
    my|Malaysia
    mz|Mozambique
    na|Namibia
    nc|New Caledonia
    ne|Niger
    nf|Norfolk Island
    ng|Nigeria
    ni|Nicaragua
    nl|Netherlands
    no|Norway
    np|Nepal
    nr|Nauru
    nu|Niue
    nz|New Zealand
    om|Oman
    pa|Panama
    pe|Peru
    pf|French Polynesia
    pg|Papua New Guinea
    ph|Philippines
    pk|Pakistan
    pl|Poland
    pm|Saint Pierre and Miquelon
    pn|Pitcairn
    pr|Puerto Rico
    ps|Palestinian Territory
    pt|Portugal
    pw|Palau
    py|Paraguay
    qa|Qatar
    re|Reunion
    ro|Romania
    rs|Serbia
    ru|Russia
    rw|Rwanda
    sa|Saudi Arabia
    sb|Solomon Islands
    sc|Seychelles
    sd|Sudan
    se|Sweden
    sg|Singapore
    sh|Saint Helena
    si|Slovenia
    sj|Svalbard and Jan Mayen
    sk|Slovakia
    sl|Sierra Leone
    sm|San Marino
    sn|Senegal
    so|Somalia
    sr|Suriname
    st|Sao Tome and Principe
    sv|El Salvador
    sy|Syria
    sz|Swaziland
    tc|Turks and Caicos Islands
    td|Chad
    tf|French Southern Territories
    tg|Togo
    th|Thailand
    tj|Tajikistan
    tk|Tokelau
    tl|Timor-Leste
    tm|Turkmenistan
    tn|Tunisia
    to|Tonga
    tr|Turkey
    tt|Trinidad and Tobago
    tv|Tuvalu
    tw|Taiwan
    tz|Tanzania
    ua|Ukraine
    ug|Uganda
    uk|United Kingdom
    um|United States Minor Outlying Islands
    us|United States
    uy|Uruguay
    uz|Uzbekistan
    va|Vatican
    vc|Saint Vincent and the Grenadines
    ve|Venezuela
    vg|British Virgin Islands
    vi|U.S. Virgin Islands
    vn|Vietnam
    vu|Vanuatu
    wf|Wallis and Futuna
    ws|Samoa
    ye|Yemen
    yt|Mayotte
    za|South Africa
    zm|Zambia
    zw|Zimbabwe
mxt’s picture

Hi RdeBoer,

I appreciate very much the help that you wanted to give me spending time on this problem: thank you very much, really.

The solution you suggest is already consolidated and used by many drupalers, and of course I had already considered it as a last resort, using in combination with http://drupal.org/project/location_taxonomize for example.

Finding out your Module I was really hoping he could help me with a much more efficient approach, without having to pre-compile a list of country (taxonomy or option values ​​that is). If everything had worked out as hoped, I would no longer have to worry about managing a list of "hard written" countries: this list will be made ​​automatically with any submission of nodes (with Location) from my users.

Do you think that there may be alternatives? Unfortunately, for example, the module Addressfield does not provide a strong integration with Views: actually is not possible to create views based on addressfield table (Location module does it), otherwise one could try that.

Maybe using a combination of Addressfield + EntityFieldQuery Views Backend (http://drupal.org/project/efq_views) + Global Views Filter could be another way to try?

Thank you so much

rdeboer’s picture

" I would no longer have to worry about managing a list of "hard written" countries: this list will be made ​​automatically with any submission of nodes (with Location) from my users."

I guess if I have some more time I could write a Global Filter custom pseudo-field (as already available for Location Proxomity) based on the country codes present in your Location table and using function location_country_name() to translate the 2-letter codes to human names.

That would be the simplest from the user's point of view, me thinks.

PS: thanks for bringing the location_taxonomy module to my attention. I hadn't heard of that one.

mxt’s picture

At the moment I've found a workaround using hook_form_alter() in this way:

function my_custom_module_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {

    case 'global_filter_1':
      $modified_options = array();
      foreach ($form['view_global_filter']['#options'] as $option) {
        if ($option == 'Worldwide') {
          // manage exception for first value 'All' (worldwide in my case)
          $modified_options[''] = $option;
        }
        else {
          $modified_options[$option] = location_country_name($option);
        }
      }
      // Assign the new modified options:
      $form['view_global_filter']['#options'] = $modified_options;
      break;
  }
}

I'm not a programmer so feel free to correct my code if necessary.

All works fine now, thanks to your previous suggestion about the use of location_country_name()

Anyway, I think a working solution "out of the box" provided by your module would be the best solution for all.

Thank you very much for considering this.

rdeboer’s picture

Looks good! Well done MXT!

As a generic solution we can't used it in its current form due to the hardcoding of 'view_global_filter' and 'global_filter_1' but great it works for you and you didn't feel the need to abandon the Global Filter module ;-)

As mentioned in #9, I'm considering implementing a generic solution for this.... just have to find the time....

Rik

rdeboer’s picture

I've just checked into the development branch a new pseudo-field "Loation: country" which pops up amongst the other (normal fields) when you configure a Global Filter block.
When the global filter is used the country list will be core's global list of 200+ countries when the Location module is NOT enabled.
However when the Location module IS enabled the list will show the countries found in Location's location table, i.e only those countries that have associated content.
Good?

mxt’s picture

It works like a charm!

Thank you very much!

Unfortunately I still have to use my solution based on Views, because I need some filter on results (e.g for content TYPE), but I think that as a general purpose this new feature will be very usefull to many.

Thanks a lot!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Dharmendra.s’s picture

Sorry guys, but i want to reopen this,
i want to use location+global filter+smart-ip but not able to fetch data from view as an argument, just like comment #5 by MXT, i import this code in our view, but in my case it shows only 2 digit country code in dropdown,
second thing,,, how we can pass this country code in view as a argument,
before that i try by taxonomy term id then it works fine with two modules (global filter+ country vocab)make country vocabulary and pass taxonomy term id as a argument in view, but with smart ip it returns country code so it creats proublem, if you have any solution then help me
i m using drupal 6.x, views 2.0, etc

rdeboer’s picture

Hi dharmendraRaj,
As stated on the project page, the module only supports Views 6.x-3.x.
I don't think converting to 6.x-3.x will solve your problem though.
I won't be doing any free development work to make this work on D6 "out of the box". I'm concentrating on D7
For a solution I suggest you follow the comments in #6 and #7 in this thread.
Rik

doppel’s picture

Same with provinces, only province code appears in the dropdown list. any work around?