When using the Countries field as a fileter in Views, no select list shows up. I tried to create a Views Filter handler my self, but I did not succeed.
Who can ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

johnv’s picture

Status: Active » Postponed (maintainer needs more info)

Sounds reasonable. I'll monitor that issue.

Alan D.’s picture

Title: Adding a Views Filter. » Views intergration
Priority: Normal » Major

There will need to be some custom work for getting views integration. Calling any views gurus to step forwards!!!

Alan D.’s picture

Status: Postponed (maintainer needs more info) » Active
rickvug’s picture

An interesting project gaining a lot of steam is Entity API (http://drupal.org/project/entity). I haven't dived in fully but it looks like basic views integration was committed recently. See http://drupal.org/node/965860#comment-3792164. Having the Countries entity derived from the base entity class provided by Entity API could be a good idea if we'd get Views integration and other integrations for free.

webflo’s picture

Status: Active » Needs work
FileSize
8.04 KB

I worked on this. Its not very much but a start. My patch is attached. Please test and give feedback.

webflo’s picture

Status: Needs work » Needs review
FileSize
11.44 KB

Here is a new patch. Its working. I added some more filters.

johnv’s picture

Webflo, I tried your code, but I did not see any difference. My views filter only contains a textfield, which was already working.
I have applied #1058464: No multiple select possible in exposed filter for CCK list field some time ago, but doesn't seem to help eiter.
I suppose I needs to get the new versions for Views and CTools?

webflo’s picture

Have you cleared the cache? Here is another patch with provides a new filter configuration form. This patch includes #1079864: Convert custom widget to use the core field options widget. to do this. You must add a relationship to your view (e.g. "Fields: Country (field_country) - iso2").

Tested with:
- Views 7.x-3.0-beta2
- Chaos tool suite 7.x-1.0-alpha4.

My github repository:
- https://github.com/webflo/countries/tree/views

johnv’s picture

I have applied the other patch, too - cleared caches. I don't need relationships if my base Entity contains the field itself?
I'll give it a try tomorrow with new versions.

johnv’s picture

Title: Views intergration » Countries - Views integration
webflo’s picture

FileSize
6.24 KB

Feature with two views. to show the relationship on a node view and countries view.

johnv’s picture

Webflo, thanks for your data. It'll take some days before I can work on it.

webflo’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Bump version. Views support is implemented in 7.x-2.x.

johnv’s picture

Status: Needs review » Needs work

This is not complete yet.
I would expect a select list and an autocomplete widget. Current implementation extends views_handler_filter_in_operator.
Check other default filters:
select list: class views_handler_filter_many_to_one extends views_handler_filter_in_operator
taxonomy: class views_handler_filter_term_node_tid extends views_handler_filter_many_to_one

johnv’s picture

addition to #15: the Views filter of Location:Country shows a Select list.

johnv’s picture

OK, I understand now. I'll just explain for future reference:
Views support for base Entity 'Countries' is very elaborate. If you want to create a Views filter for base Entity 'Content' do the following:
- create a Content type with e.g. field = field_country, name = 'Country';
- create a View for 'Content';
- create a Relationship (under 'Advanced') to 'Content: Country - iso2';
- create a filter of type 'Countries: xyz' with the new relationship.

johnv’s picture

First thing: I like your very elaborate work! Also the 'field based configuration' option in the filter is very good!

Some 'Needs work':

'ISO2 - list' is not sorted alfabetically; I imagine for ISO3 goes the same;

When adding a relationship, I have to choose between these options:
-- Content: {fieldname}
-- Content: {fieldname} (field_country) - iso2
-- Content: {fieldname} (field_country) - delta <-- this only for multi-value fields
The first is the easiest choice, but the wrong one. Does that option have a function, or can you remove it from the list? This option isn't shown on other multivalue fields either. It generates this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_country.field_country' in 'on clause'

When adding the filter, you have the option 'custom'.
- I expect the field widget back, but I don't :-(. Is this still WIP? Otherwise, I'd change the name to 'all countries' or 'normal';
- The option 'field base confguration' is awesome!
- I only have these options at e.g. 'ISO2-list', not with normal 'ISO2'

When adding the filter 'xxx - list', you have the option 'select all'. This is confusing: filter works fine if you do not choose anything here, but you suggest one MUST make a selection. What happens if someone does choose this option, and a new country appears? it doesn't get in the list. This option might be handy if you first select all and then deselect the few you don't want. But: is that a valid use case? You might consider creating a checkbox below the select list.

When adding the filter 'xxx', The autocomplete is not working, I get a normal textbox. That's a pity. I don't think a normal textbox is useful for the user.

Merlinofchaos has recently rewritten the Taxonomy-filters. Country can resemble that a bit more.
Step 1: choose 'Taxonomy term: Term - Taxonomy term chosen from autocomplete or select widget.'
Step 2: choose autocomplete/select list
For Countries:
Step 1: choose 'Countries: ISO3 - Country chosen via ISO3 from autocomplete or select widget.'
Step 2: choose autocomplete/select list + field_based_config/custom
or
Step 1: choose 'Countries: Country chosen from autocomplete or select widget.'
Step 2: choose ISO2/ISO3/Name/.. + autocomplete/select list + field_based_config/custom

The latter seems like a rewrite, but You might consider it in moving from textbox to autocomplete.

Conclusion: Above issues are merely UI stuff. Working with Countries-filter is pretty complicated, but is similar to the new Taxonomy-system

Apart from the autocomplete, I consider this RTBC.

johnv’s picture

An update suggestion for the project page. It does not reflect your work:
Views Integration
The module supports Views fields. Views filters is supported via 'select list' in the following way:
- create a Relationship (under 'Advanced') to 'Content: Country - iso2' ('Country' being the field label);
- create a Filter of type 'Countries: xyz' with the new relationship.
I will accept patches here: #1061156: Countries - Views integration

Alan D.’s picture

I've updated the project page a bit to reflect the status of this issue.

@John: Thanks for the suggestion.

berenddeboer’s picture

johnv, great trouble following what you mean.

1. Are you saying I can get a select instead of text field?

2. Is that in 1.0, or is that in the dev version?

berenddeboer’s picture

OK, I tried 2.x-dev, nothing changed. I have a relationship to my country field. I have a filter on this country field. But it still only displays the text box, not a select.

webflo’s picture

There are different filter handler. Try "Countries: Name - list". I work on new filters, as proposed by johnv in #18.

berenddeboer’s picture

Just don't see that filter. When I add a filter, I only see my country field, nothing with list.

johnv’s picture

FileSize
5.29 KB
56.1 KB
34.21 KB
40.34 KB

Berend, perhaps these screendump will help you.

Jerome F’s picture

Even with the translation relationship, the country field name is not translated when you use it in views. Even though country names translations are saved in the translation interface.

Cyberwolf’s picture

The views filter seems to be broken on the recent dev releases of Views. When adding it, it says "No valid values found".

It looks related to http://drupal.org/node/1207680, the proposed fix there is adding an empty validate() method to the views filter handler:

  function validate() {}

Adding this to the countries filter handler seems to fix the problem there as well.

dolphinonmobile’s picture

This creates another problem, if you have an unlimited choice of entries for a country field, and create a relationship for it in a view, the view will create duplicate nodes in its output, a duplicate for each multiple value entered.
So if node 'x' has 3 countries selected, the view will output node 'x' 3 times.

johnv’s picture

@_raywan, isn't this the case for ANY multi-value field?

dolphinonmobile’s picture

Well, is it? I don't know, this is the first time Iv tried. But if it is as you say, then is there no other support for views filters other than via the relationship route?

johnv’s picture

The views relationship model of countires is equivalent of that of a term reference field. Suppose you have a node with a Countries field and a Term Reference field: for the Term reference field you can create a 'simple' dropdown/selectlist for tid/name. If you need more, you need to create a new relationship 'terms of this node'. Idem for Countries. Webflo's implementation resembles Term Reference. Indeed, it is cumbersome, but since Views sets the standard, it is sufficient, and it provides access to all subfields of Countries. - you'll have to learn how to use the relationships to get the full out of views anyway.
But no-one stops you from supplying a patch with the direct views-field! ;-)

johnv’s picture

Priority: Major » Normal
dolphinonmobile’s picture

Ok.

webflo’s picture

@ _raywan: Just enable the "Distinct" in Query settings for your view, until there is a better solution.

webflo’s picture

@ Cyberwolf: #1207680: No valid values found (6.x-3.x-dev & 7.x-3.x-dev) if fixed. There is no validation problem with views 7.x-3.x dev (2011-10-17).

webflo’s picture

Status: Needs work » Fixed

Marking this issue as fixed. Everything else around views integration is a follow-up.i mark this issue as fixed. Everything else around views integration is a follow-up.

Alan D.’s picture

I've updated the project page to reflect this too.

Status: Fixed » Closed (fixed)

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

hkovacs’s picture

Issue summary: View changes

#25 works for me.