I am not sure if what I want to do is possible using Views.

I want to create a View in order to filter nodes by author and/or by city (City is a Taxonomy field). I have created it and it seems to work well in all cases except when the first contextual filter does not validate. I mean:
http://www.mywebsite.com/page/user1/barcelona shows all nodes of user1 from barcelona: works OK
http://www.mywebsite.com/page/user1 shows all nodes of user1: works OK
http://www.mywebsite.com/page/user1/undefined shows all nodes of user1: works OK
http://www.mywebsite.com/page/undefined/barcelona should show all nodes from Barcelona but it doesn't: it doesn't work

I attached the view in this bug. There are two contextual filters. First one is "Author uid":

  • When the filter value is NOT in the URL: Display all results for the specified field
  • When the filter value IS in the URL or a default is provided:
    • Specify validation criteria
    • Validator: User
    • Type of user filter value to allow: Only allow string usernames
    • Action to take if filter value does not validate: Display all values...

And "City" filter:

  • When the filter value is NOT in the URL: Display all results for the specified field
  • When the filter value IS in the URL or a default is provided:
    • Specify validation criteria
    • Validator: Taxonomy term
      • City
    • Filter value type: Term name converted to Term ID
    • Transform dashes in URL to spaces in term name filter values
    • Action to take if filter value does not validate: Display all values...

Thank you in advance.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drupal12user’s picture

I have the exact same problem. I have 4 contextual filters, and if one doesn't validate (for which i choose to display all values for that field if it doesn't validate), all the following filters are not taken into account. Could this be a Views bug?

However, a solution would be to use the "Exception value" in the ContextualFilter "When the filter value is NOT available" part. Instead of using "undefined" you can use the "all" value (or even "undefined" but you have to make "undefined" as "Exception value"). I think this is because, before checking the availability of the filter, Views checks if the provided value validates the existing Taxonomy terms?

Aljullu’s picture

Thank you. I didn't know about "Exception value" and I think I could solve my problem with this trick. Thank you again, you saved me to spend a lot of time writing SQL queries manually.

jpstrikesback’s picture

Just trying to figure this out myself. I have multiple page displays with contextual filters all set to validate or show page not found like so:

blogs
blogs/author
blogs/author/year
blogs/author/year/month
blogs/year
blogs/year/month

Yesterday they worked, when author had no results but year did the display that validated showed...today they are clobbering each other, very very odd, and I'm wondering if what worked was intended on unintended behavior now!?

By clobbering I mean the behavior drupal12user details whereby if one validate action takes place subsequent displays don't get a chance to execute or something...

My workaround is adding a differentiating path component:

blogs/year
blogs/year/month

becomes

blogs/all/year
blogs/all/year/month

jpstrikesback’s picture

Version: 7.x-3.3 » 7.x-3.5
Category: support » bug

Gonna call this a bug and play with it a bit more today

jpstrikesback’s picture

Category: bug » support

Changing this back, I see old views docs saying that the only thing choosing between matching paths in one view is access, I don't know if that's still the case, but it's likely.

anewholm’s picture

line 865 of views.inc:
else {
// determine default condition and handle.
- $status = $argument->default_action();
break;
}

should be:
else {
// determine default condition and handle.
$status = $argument->default_action();
+ if ($status !== TRUE) break;
}

anewholm’s picture

FileSize
346 bytes

this is the patch to add the $status check in

anewholm’s picture

FileSize
346 bytes

just try that again...

MustangGB’s picture

Status: Active » Closed (outdated)

Closing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.

philsward’s picture

I had a similar issue as described.

Oddly, I deleted all of the contextual filters and re-created them again. Then it "magically" worked. I had this problem on two different view pages within the same view. It makes me wonder if something didn't save properly which corrupts the DB and deleting then re-creating the contextual filters saves it proper.

I could be grasping at straws in a complete coincidence too...