error "The operator is invalid" appears when adding "Location:country" to filter Views.

No problem if it's "Location:City", "Location:Province", "Location:Phone"
No matter whether filter is exposed or not.

I have a content type of "Job Post", where location is enabled, and I try to filter by country.

I use latest dev. versions:
Location -Jul-17
and
Views - Jul-21

Comments

clashar’s picture

Component: exposed filters » Miscellaneous

I've just tried Location 7.4 dev, the same error

dawehner’s picture

Project: Views (for Drupal 7) » Location

This seems to be a bug of location module?

clashar’s picture

dereine, thanks for pointing, I wasn't sure of which module could bug belong to.

justmagicmaria’s picture

Same issue. Subscribing.

salientknight’s picture

Same issue... started happening after last weeks views upgrade.

Matayou’s picture

Subscribing, similar issue

mmilo’s picture

This can be fixed if location_handler_filter_location_country uses the default parent class... ie:

class location_handler_filter_location_country extends views_handler_filter_in_operator {

becomes

class location_handler_filter_location_country extends views_handler_filter {

Rather tired to make a patch.

justmagicmaria’s picture

@mmilo Actually, when I make that change I get:

Fatal error: Call to undefined method location_handler_filter_location_country::operator_values() in /Users/mariagreene/projects/dollinghouse/drupal7/sites/all/modules/location/handlers/location_handler_filter_location_country.inc on line 43

dgastudio’s picture

same error

vensires’s picture

This also happens on 6.x-3.x-dev after the last week upgrading

ankur’s picture

Priority: Major » Normal
Status: Active » Needs review
StatusFileSize
new4.19 KB

Looks like there are several issues with the country filter.

Here's a patch for the 7.x-3.x branch that tries to address them. If you do test it, please post back here with your results.

Sinovchi’s picture

I manually applyed patch #11 to latest dev version of location - 6.x-3.x-dev. It works for single country only. For multiple countries it returns error:
warning: mysql_real_escape_string() expects parameter 1 to be string, array given in Z:\home\mydomain.loc\www\includes\database.mysql.inc on line 329.

Nevertheless, thanks for the patch.

ankur’s picture

@biarr in #12,

The patch is only intended for location 7.x-3.x, when being used with views 7.x-3.x.

I think location 6.x-3.x might still only be compatible with views 6.x-2.x, but not with views 6.x-3.x.

revjtanton’s picture

I have applied this patch and my versions are correct...nothing changed at all.

Should I delete my old views and make new ones?

vensires’s picture

In 6.x as stated in #12 the filter works for only one country. As for 7.x I do not know. The only sure thing is that after applying the patch, your views will be immediately ready. You will only have to reconfigure the country filter. No need to recreate the whole views.

Tino’s picture

Couldn't patch #11 automatically, so I applied it manually to location_handler_filter_location_country.inc. It does do the trick tough. Thanks! Hope it will be fixed in the next 7.x-3.x-dev release.

uniqode’s picture

I have applied this patch but i'm getting an error
Call to undefined method location_handler_filter_location_country::operator_values()

uniqode’s picture

it should be
class location_handler_filter_location_country extends views_handler_filter_in_operator
and not
class location_handler_filter_location_country extends views_handler_filter

as views_handler_filter_in_operator already extends views_handler_filter

but otherwise patch works, thanks

ankur’s picture

@emelja: If the parent class doesn't define the method, then this class should take it from the grandparent class.

I'd say make sure you're using the latest versions of everything and maybe clear all of your caches.

simon_s’s picture

Patch #11 works fine here with the current 7.x-3.x-dev. Thanks!

revjtanton’s picture

The patch did not work for me, however I found the same problem @emelja33 found and now it works.

pasqualle’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new4.2 KB

same patch, just removed trailing spaces.. named Ankur as the patch author..

pasqualle’s picture

just for the record, multiple selection of countries works correctly..

Refineo’s picture

I applied patch #22 to my environment:

- Drupal 7.10
- Location 7.x-3.x-dev
- Views 7.x-3.x-dev

The following two errors are solved:

1) When trying to edit view filter criteria:
admin/structure/views/view/frontpage/edit

Configure filter criterion: Location: Country

Notice: Undefined index: single in location_handler_filter_location_country->operator_options() (line 87 of /***/sites/all/modules/contrib/location/handlers/location_handler_filter_location_country.inc).

(SOLVED)

2) After saving the view there was an error:

The operator is invalid on filter: Location: Country.

(SOLVED)

Remaining issue

However now after applying this patch #22 when I select country (United States) from the exposed filter list, there is no content shown in the view although there is a published content node assigned to that country location.
When I select - Any - in a country exposed filter, I can see all records as expected.

pasqualle’s picture

@refineo:
- enable "Show the SQL query" on the admin/structure/views/settings page
- try the preview button on the view edit page
- examine the sql, there should be something like:
"... WHERE ... location.country = 'us' ..."
- go to the database, make sure you have 'us' in the location table country column..

Refineo’s picture

ok, I reinstalled this and patched the module again and now #23 - #24 works fine.
It was != 'us' instead of == 'us' before in sql.

Refineo’s picture

IMHO this is RTBC. Will you commit this patch soon ? Thank you !

ankur’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Thanks for the updated version of the patch in #22.

I went ahead and committed it to the 7.x-3.x branch.

pipep’s picture

Patch on #22 worked for me on D.7.10

However I have a question if anyone can help... I can't figure it out.

I have a content type with location required. I'm using views to show an excerpt of the nodes, and I want to filter them by country (the one the user selected when creating the node)

How can I filter the list of countries displayed on the dropdown, to only the ones that have nodes already created ?

let's say I have only 10 countries with related nodes, the dropdown should show only those. If a user adds a node with a new country, it should appear on the dropdown automatically...

Josh Benner’s picture

Patch in #11 rolled against 6.x-3.x-dev -- seems to be working? Haven't heavily tested yet.

Goekmen’s picture

I still get all countries with the latest dev version, what I am doing wrong?
The patch seem to be included.

aasarava’s picture

Patch in #30 seems to work on 6.x-3.x-dev.

Sinovchi’s picture

Patch in #30 works for single country only (when you select "Force single" in view). For multiple countries it still returns error:
warning: mysql_real_escape_string() expects parameter 1 to be string, array given in ...\includes\database.mysql.inc on line 329.

darrellduane’s picture

Patch #30 also doesn't work for Filters that are not exposed in 6.x-3.x.

hongpong’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Closed (fixed) » Needs work

re-opening this to 6.x and needs work, as we have a partial patch and this needs work! Really annoying, in my case it won't accept 1 country. Just need US & Canada to work as exposed filters!! [I think it's not overkill to just use this thread instead of opening a new one, since a 6.x conversation is developing]

darrellduane’s picture

@HongPong thanks for reopening this, I'm not seeing this patch working for me under 6.x-3.x of views and am thankful that you validate my reality in this.

darrellduane’s picture

@HongPong thanks for reopening this, I'm not seeing this patch working for me under 6.x-3.x of views and am thankful that you validate my reality in this.

hongpong’s picture

In my case I am having trouble with a data set of US and Canadian Location entries, and the State/province level filter fails to recognize canadian provinces (the site info is set to United States which I gather may be related), as well as experiencing this error. (i figured maybe letting people pick US/Canada on the exposed filter might prompt it to let select the provinces - then i ran into this bug). It seems like Location has a myriad of issues with Views 3.x :/

general_ludd’s picture

Component: Miscellaneous » Location_views

I too am struggling with this particular property of the location module. No matter which way I try to configure the filter, it doesn't work. Without the country, the state/province filter only seems to work for the United States (in my case) and we have Canadian entries that need to be included in the filter. Poor Canadians.

hongpong’s picture

it seems like the patch on #30 improved matters quite a bit. I had to apply it manually but it does make the multi-country exposed filter (selecting a single country, Canada, and causing the province to auto-fill, only for provinces that have 1+ result). So that is good news, thanks Josh Benner!

yannickoo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.97 KB

Can confirm that #30 works for current development version. I just re-rolled the patch so that it is easy to apply with Git.

podarok’s picture

Status: Needs review » Active

bot recall

podarok’s picture

Status: Active » Needs review

bot

podarok’s picture

Status: Needs review » Fixed

#41 pushed to 6.x-3.x-dev
Thanks!

Status: Fixed » Closed (fixed)

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