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;| Comment | File | Size | Author |
|---|---|---|---|
| #5 | global filter views results.jpg | 85.01 KB | mxt |
Comments
Comment #1
mxtAny response on this?
thank you very much
Comment #2
rdeboerHi 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
Comment #3
mxtHi 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:
I'm missing something?
Thank you!
Comment #4
rdeboerHi 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
Comment #5
mxtThank 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):
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:
I don't know what to do, please help me!
Thank you
Comment #6
rdeboerHi 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.
Comment #7
rdeboerHere's a list of country codes and names that you can use to create your own country field.
Comment #8
mxtHi 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
Comment #9
rdeboer" 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.
Comment #10
mxtAt the moment I've found a workaround using hook_form_alter() in this way:
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.
Comment #11
rdeboerLooks 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
Comment #12
rdeboerI'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?
Comment #13
mxtIt 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!
Comment #15
Dharmendra.s commentedSorry 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
Comment #16
rdeboerHi 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
Comment #17
doppel commentedSame with provinces, only province code appears in the dropdown list. any work around?