Problem/Motivation

I am attempting to update my view's filter criteria to something like (A and B and C) and (D or E or F).

The admin UI in the modal pop-up appears to work: I can add a new filter group, drag the specific filters to the right group, and change the ANDs and ORs — but when I click the "Apply (all displays)" button, all of my updates disappear. I land back to the main admin screen and my changes are gone.

I also see an error in the watchdog log:

  • Type: form
  • Location: .../admin/structure/views/ajax/rearrange-filter/VIEWNAME/webform_select_1/filter
  • Referrer: .../admin/structure/views/view/VIEWNAME/edit/webform_select_1
  • Message: Illegal choice 2 in filters element.
  • Severity: error

This used to work; I've used this functionality relatively recently. And older views with more complicated filter groups and operators continue to work correctly, if they were created before this broke. So something must have changed fairly recently.

Does anybody have any ideas what might be causing this problem?

Steps to reproduce

  1. Create a view with multiple filter criteria
  2. Next to "Filter criteria", click "And/Or, Rearrange"
  3. In the modal pop-up click "+ Create new filter group"
  4. Drag a couple of the filter criteria to the new filter group
  5. Click "Apply (all displays)" or "Apply (this display)"
  6. Your changes are gone.

Issue fork views-3348800

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

BerkeleyJon created an issue. See original summary.

dcloganguy’s picture

We are having the same issue.
Drupal 7.95
Views 7.x-3.27
If I try to filter something like below, it does not save and throws an error. Steps to reproduce are the same as above.
Error:form Illegal choice 2 in filters element.

Content: Published status No
And
Content: Type = Basic page

OR
Content: Type = Book page

thanks

rclemings’s picture

Same here with Drupal 7.95 and Views 7.x-3.29, and with Views 7.x-3.28 on another site.

It looks as if this has been a problem for some time, if unnoticed until now. I rolled back as far as 3.25 and it was still an issue, as far as I could tell.

rimu’s picture

I recently upgraded to PHP 8.2 from 7.2, maybe that is related.

damienmckenna’s picture

Are you all using PHP 8.2?

rclemings’s picture

PHP Version 8.1.18 here.

berkeleyjon’s picture

PHP 8.1.18 here, too.

wrg3@calvin.edu’s picture

We're seeing this as well. Our system:

  • PHP 8.1.14
  • Drupal 7.97
  • Views 7.x-3.29

FWIW, we were able to reproduce this on every PHP 8.1-compatible Views release.

We downgraded our PHP version to 7.4 and this immediately began working again.

wrg3@calvin.edu’s picture

We just attempted a PHP downgrade, which resolved the issue.

Curiously, once we downgraded, an empty filter group was immediately visible.

damienmckenna’s picture

Version: 7.x-3.29 » 7.x-3.x-dev
Issue summary: View changes
Issue tags: +PHP 8.1

Sounds like a PHP 8.1 compatibility bug then.

attekilpela’s picture

I checked this and probably found the bug, but I'm not sure where it actually is:
1. User click Create new filter group and AJAX is executed to menu callback $items['admin/structure/views/ajax/%/%views_ui_cache']
https://github.com/drupalprojects/views/blob/7.x-3.x/views_ui.module#L135

2. Function views_ui_ajax_form is executed with parameters: $js = TRUE, $key = rearrange-filter, $view = views name
https://github.com/drupalprojects/views/blob/7.x-3.x/includes/admin.inc#...

3. $key is reassigned in line 3015 $key = key($view->stack); and is assigned to zero.
https://github.com/drupalprojects/views/blob/7.x-3.x/includes/admin.inc#...

4. Then comparison $view->form_cache['key'] != $key where values are rearrange-filter and 0 which in PHP7 is FALSE and PHP8 is TRUE. The comparison of course should be between rearrange-filter and rearrange-filter.
https://github.com/drupalprojects/views/blob/7.x-3.x/includes/admin.inc#...

kristofferwiklund’s picture

Finding the same problem. Looking in to it. But it seems the the references @attekilpela has, is to an old github version of Views. The correct urls should be to here: https://git.drupalcode.org/project/views/-/blob/7.x-3.x/includes/admin.inc

kristofferwiklund’s picture

So we have found code that seems have never been run in PHP 7. But as logic in PHP 8 has been changed (to the better) its now running and breaks views.

In code admin.inc:3096 https://git.drupalcode.org/project/views/-/blob/7.x-3.29/includes/admin.... we have the following row:

if (isset($view->form_cache) && $view->form_cache['key'] != $key) {
unset($view->form_cache);
}

When adding a filter group $view->form_cache['key'] will be "rearrange-filter" and $key will be "0"

And in PHP 7: $view->form_cache['key'] != $key is FALSE. As "rearrange-filter" is converted to int,0. So 0!=0 is FALSE.
And in PHP 8: $view->form_cache['key'] != $key is TRUE. As $key is converted to string ''. So "rearrange-filter" != '' is TRUE.

(More info here: https://wiki.php.net/rfc/string_to_number_comparison#introduction)

The affect of this is that that form_cache is clear the the form is not updated.

I have tried setting a break point in PHP7 on the "unset($view->form_cache);" row. And that has never been triggered for me.

So the solution for me is to remove the if code.

joelpittet’s picture

Status: Active » Reviewed & tested by the community

This change is working well. Thanks @kristofferwiklund for digging into the details.

damienmckenna’s picture

FYI that code section comes from #118672: Adding sql ORing capability with filters and hasn't changed in 13 years.

damienmckenna’s picture

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you everyone!

Status: Fixed » Closed (fixed)

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