So, I want to make available to the users 3 terms from a certain vocabulary as a drop down list. So, I use the operator "Is one of" (and specifically mark the three terms in question) AND "Limit list to selected items". The logic/expected behavior would then be:

The user gets these three terms to choose from in the drop down list.

This is, however, not the case, since the option "Any" is suddenly inserted as default - resulting in nodes containing ANY term from the ENTIRE vocabulary (not only the three marked ones) being showed to the user. It seems that the operator "Is one of" is then being ignored. Seems like a bug, not a feature.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thomas1977’s picture

Anyone?

thomas1977’s picture

When deselecting "Limit list to selected items", -Any- is removed as an option from the exposed filter drop down list (as wanted). So, why is -Any- inserted into the drop down list as the DEFAULT selection when "Limit list to selected items" is selected? And how to do we get rid of it? We ONLY want nodes with one of the three SELECTED terms to be showed to the user (NOT any nodes with terms from the entire vocabulary).

Need help on this one. And I'm convinced that some of the more seasoned users/devs here can come up with a solution :-)

thomas1977’s picture

Could still use some help on this one.

dawehner’s picture

Title: Bug when using operator "Is one of" and "Limit list to selected items" - 'Any' shouldn't be an option » When using operator "Is one of" and "Limit list to selected items" - 'Any' shouldn't be an option
Status: Active » Postponed (maintainer needs more info)

Please don't push issues like this, people work hard to the queue so everything below 2 weeks is fast. If you think no, have a look at the amount of issues :)

So you created an issue in the views issue queue so you saw http://drupal.org/node/571990 didn't you?
Please for example describe what kind of filter behaves like this... therefore an export of the view would have answered it automatically.

Another question is whether you have selected "optional" or not.

thomas1977’s picture

dereine, thanks for the info and link. Much appreciated. And thanks for all the hard and brilliant work that's being put into this project! Never intended to sound unappreciative - just worried that the issue was forgotten and burried deep inside the issue mountain :-) A couple of weeks is to be expected for a reply - no problem.

This is a pinned out version of the issue:

1) I have a vocabulary 'Car makers' consisting of 10 terms (Honda, Chrystler, Ford, Opel, VW, Fiat, Volvo, Saab, Audi, Toyota)
2) I could now make a simple view that returns all nodes tagged with any of these 10 terms. But that's not what I want.
3) I want to make a view of nodes that are tagged with any of 3 specific terms from the vocabulary -> in other words: term Fiat, Volvo, or Saab must be present in the specific view.
4) I therefore create the view and insert filter 'Content: Has taxonomy terms (with depth)' and choose my vocabulary 'Car makers' + select 'drop down list'.
5) I then select operator 'Is one of' and specifically mark the 3 terms Fiat, Volvo, and Saab in the list of the 10 terms total.

So far, no problems. The view works perfectly. The view shows all nodes that are tagged with any of the three selected terms. However, it's important for our site that the user can choose WHICH of the 3 terms he wants to filter by (Fiat, Volvo, or Saab).

6) In the filter I therefore continue and select 'Expose this filter to visitors, to allow them to change it' and then select 'Limit list to selected items' (with Fiat, Volvo and Saab checked).

Expected behavior: the view, by default, returns the exact same results as before, but with the drop down list to choose from.
Actual behavior: the view does not return the same results as before, but returns a list of nodes tagged with ANY of the 10 terms from the entire vocabulary 'Car makers'. The drop down list is presented to the user, but has 4 options (and not 3): 1) -Any- 2) Fiat 3) Volvo 4) Saab. And -Any- is the default option chosen by Views.

It wouldn't be a problem that -Any- gets inserted as an option, if only 'any' meant 'any of the 3 terms that was checked in the filter'.

Does use case scenario make sense? Hope so... I can attach the view if needed.

dawehner’s picture

Category: bug » feature
Status: Postponed (maintainer needs more info) » Active

Well sure this feature absolute makes sense and is sometimes what you want but often people expect another behaviour, so technical it's a new feature.

It's somehow hard to think what's the best way to bring this into views in a general way, perhaps you could write some custom code here to solve it first for you own. You are welcomed to make a generalized addition to views.

thomas1977’s picture

Unfortunately, I don't have sufficient coding skills - wish I had! To maybe make it easier to figure out what needs to be done on the coding side of things, here is an illustration of the use case (our site doesn't operate in the car business, so it's just for illustration purpose):

Vocabulary 'Car makers' with terms: Honda, Chrystler, Ford, Opel, VW, Fiat, Volvo, Saab, Audi, Toyota.

View 1: 'American cars'. Term filter -> 'Car makers' -> Operator "Is one of" -> Chrystler, Ford -> Exposed filter -> Limit selection to selected terms (Chrystler, Ford)
End user drop down list
|Either Chrystler or Ford|
|Chystler|
|Ford|

View 2: 'German cars'. Term filter -> 'Car makers' -> Operator "Is one of" -> Opel, VW, Audi -> Exposed filter -> Limit selection to selected terms (Opel, VW, Audi)
End user drop down list
|Either Opel, VW or Audi|
|Opel|
|VW|
|Audi|

View 3: 'Swedish cars'. Term filter -> 'Car makers' -> Operator "Is one of" -> Volvo, Saab -> Exposed filter -> Limit selection to selected terms (Volvo, Saab)
End user drop down list
|Either Volvo or Saab|
|Volvo|
|Saab|

View 4: 'Japanese cars'. Term filter -> 'Car makers' -> Operator "Is one of" -> Honda, Toyota -> Exposed filter -> Limit selection to selected terms (Honda, Toyota)
End user drop down list
|Either Honda or Toyota|
|Honda|
|Toyota|

And so on.

Sinan Erdem’s picture

In this issue, I agree with thomas1977.

I have an exposed filter of content types. I limit the list to selected ones. But there is -any- option and by default, this view shows all the content types, which is unwanted. Using the latest Views version...

Nephele’s picture

Title: When using operator "Is one of" and "Limit list to selected items" - 'Any' shouldn't be an option » When using operator "Is one of" and "Limit list to selected items" - 'Any' should not ignore the selected items.
Category: Feature request » Bug report
Issue summary: View changes
Status: Active » Needs review
FileSize
1.02 KB

I've switched this back to bug report instead of feature request because the requested feature does already exist in the code -- it's just not working properly because of a typo.

In my tests, the attached patch fixes the issue. The '-Any-' option still appears in the list, but selecting it displays only items that match the selection specified in '"Limit list to selected item".

The source of the problem is that one line of code in views_handler_filter_in_operator.inc refers to a nonexistent option, 'limit'. However, the correct machine name for the "Limit list to selected item" option is 'reduce'.

David_Rothstein’s picture

This seems like a clear bug and the patch looks correct... however, it could be a bug that morphed into a feature at some point?

In other words, the current help text on the "Limit list to selected items" (which says "If checked, the only items presented to the user will be the ones selected here") is not 100% clear that it's also supposed to modify the behavior of the "Any" option. Personally I do interpret it that way, but this patch will change the behavior of views in a way some people might not be expecting.

Would another solution be to add a separate checkbox on the configuration form for this specific purpose, and have the code check that rather than $this->options['expose']['reduce']?

David_Rothstein’s picture

This patch also mainly makes sense if the filter operator is "Is one of". If it's set to "Is not one of" then things get... confusing. Because then the "Any" option in the exposed filter goes from actually meaning "Any" to instead meaning something like "Anything that is not one of the other options in the dropdown".

SocialNicheGuru’s picture

this worked for me according to what is outlined in introduction.

nithinkolekar’s picture

Status: Needs review » Reviewed & tested by the community

worked with user views also..

devad’s picture

Pathch #9 works for me for content type exposed filter. Thanx Nephele.

But it doesn't work for exposed term reference field filter. The list is not reduced to selected referenced terms but it displays content referencing all terms from vocabulary as described in #5.

colan’s picture

We've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.

If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.

We apologize for the trouble, and appreciate your patience.

Nephele’s picture

Per request, I'm re-uploading the patch

colan’s picture

Status: Reviewed & tested by the community » Needs work

#10, #11, and #14 should be addressed before we commit this.

dtamajon’s picture

I have added an additional condition on term node filter, because it was ignoring the reduce when the filter is not required.

dtamajon’s picture

Patch reviewed... in some views limit is not declared and raise an error. Condition updated to avoid such error.

SocialNicheGuru’s picture

git apply views-use_reduce_option_when_any_selected-1309578-19.patch
fatal: corrupt patch at line 26

dtamajon’s picture

Looks like an error on EOF char... can you try to apply it manually only for testing purpose?

giupenni’s picture

I've applied it manually and works like a charm!

brad.bulger’s picture

this check on 'limit'
&& !empty($this->operator['limit']) && !$this->operator['limit']
is self-contradicting, isn't it? any value that resolves to FALSE will cause empty() to return TRUE.

if the idea is to make sure that limit is not set to some non-empty value, i think you could just do
&& empty($this->operator['limit'])

i'm not sure i understand the purpose of adding that test there, though. since the line before the patch didn't reference $this->operator['limit'], how could it have been causing an error if it wasn't set? i see, this was compared to patch 18 not 9. so i think this reroll matches the original intent of patch 18.

dtamajon’s picture

@brad.bulger, I included the double check because I found a case in which $this->operator['limit'] was not defined and an error was raised. You could replace it by array_key_exists.

And yes, you can replace
&& !empty($this->operator['limit']) && !$this->operator['limit']

for
&& empty($this->operator['limit'])

From my point of view, you will get a better performance, but a sentence harder to understand for maintenance.

brad.bulger’s picture

but those are not equivalent. the first one will never test TRUE, its first half contradicts its second half. there is no value such that !empty(value) and !value are both true.

if what you want to do is only bail when the field is not required and has no value and there is no limit, then empty($this->operator['limit']) will work whether operator['limit'] is defined or not.

dtamajon’s picture

There is one difference. You are assuming that when limit is not set is equivalent to set it to FALSE. I don't remember the exact case and I should search for it, but in here I'm assuming that "not set" is equivalent to TRUE.

So, the condition is solved only when the "limit" is set and its value is FALSE. And it is not solved if "limit" is not set or if "limit" is set to TRUE.

brad.bulger’s picture

that's not how it works. empty($array['index']) returns TRUE if the key "index" does not exist in $array.

if you only want to bail when $this->operator['limit'] does exist and has a false-ish value, it depends on if you want to include NULL. if you do, you'd have to use array_key_exists() and then !. if not, you can just use isset() and !.

if it is ok to bail when $this->operator['limit'] either doesn't exist or is false-ish, then you can just use empty()

probably details about some actual cases where this matters would help to clarify things.

dtamajon’s picture

Some other way of writing the same logic (I add all the explicit checks):

isset($this->operator['limit']) && !is_null($this->operator['limit']) && $this->operator['limit']===FALSE

that could be simplified as (!is_null($this->operator['limit']) is already tested on left and right):
isset($this->operator['limit']) && $this->operator['limit']===FALSE

So, in that case we want "not set", value "null" and value "TRUE" are equivalent. Only explicit value "FALSE" accomplish the condition.

giupenni’s picture

In a new website I'm using #19 with Views 3.18 + Drupal 7.57 and works as I expected

devad’s picture

Deleted comment... as not relevant any more.

abarpetia’s picture

This is my personal opinion: I don't see this as a bug because when we say "any" that's mean any node item and "Limit list to selected items" means filter out un-selected items from the list (not actual result/node item). If we want future filter it down to only display certain node item/taxonomy item then we can add another hidden filter with restriction.

It worked for me.

We can add this in documentation (if already not available). I personally not fill to make any code changes but leave this decision on Module maintainer.

devad’s picture

Status: Needs work » Closed (works as designed)
Related issues: +#3133906: "Limit list to selected items" checkbox - Title and description adjusting

Re: #31

I agree. Very similar D8 issue created few days ago is Closed (works as designed) - with detailed explanation why. So, I suppose we can close this D7 issue as well.

However, due to not so precise use of words in "Limit list to selected items" checkbox title and description for all D7/D8/D9 drupalers who will come for the first time to this checkbox in the future - there will always be two ways how they can understand the checkbox functionality.

So, I have started an initiative to alter checkbox title and description in order to make their meaning more precise and to avoid any further misunderstandings about "Limit list to selected items" checkbox proper use.

Please, feel free to join D9 Support Request: #3133906: "Limit list to selected items" checkbox - Title and description adjusting