Problem/Motivation

Numeric views filter (\Drupal\views\Plugin\views\filter\NumericFilter) and all child filters (Date, SearchApiDate, etc) throw a php notice (PHP < 8) or fatal error (PHP >= 8) when using grouped exposed filters with a group identifier that doesn't match the filter identifier.

Notice: Undefined index: value in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput()

or

TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\filter\Date->acceptExposedInput()

Steps to reproduce

(require updates)

  1. Install Drupal standard profile
  2. Edit the default Content view at /admin/structure/views/view/content
  3. Add an "Authored on" filter
  4. Select "Expose this filter to visitors, to allow them to change it"
  5. Select "Grouped filters"
  6. Change the "Filter identifier" value from "created" to "date"
  7. Set the Grouping 1 label to "Last week", operator to "Is greater than", value type to "An offset from ..." and value "-7 days"
  8. Press Apply and then Save
  9. Navigate to /admin/content
  10. Set the "Authored on" filter to "Last week" and press "Filter".
  1. Expected behaviour: Filter is applied, correct results are shown
  2. Incorrect behaviour: error or notice when pressing "Filter"

Proposed resolution

Update \Drupal\views\Plugin\views\filter\NumericFilter::acceptExposedInput to target the exposed group identifier as per patch in #48.

Remaining tasks

  1. Add an automated test;

Workaround

If the Filter identifier is left unchanged when configuring the numeric views filter, then this bug will not be triggered.

CommentFileSizeAuthor
#184 2825860-184.patch2.26 KBadel-by
#183 2825860-183.patch2.02 KBfabianfiorotto
#178 2825860-176.patch1.86 KBrsych
#175 2825860-175.patch1.9 KBsmitghelani
#165 views.view_.content.yml20.34 KBxurizaemon
#146 core-notice_in_numeric_filter-2825860-146.patch5.33 KBdewalt
#143 2825860-undefined-index-in-NumericFilter-143.patch12.96 KBxurizaemon
#143 interdiff-2825860-143.txt660 bytesxurizaemon
#139 interdiff_137-139.txt8.65 KBakram khan
#139 2825860-139.patch13.17 KBakram khan
#138 2825860-nr-bot.txt2.04 KBneeds-review-queue-bot
#137 core-notice_in_numeric_filter-2825860-137.patch5.25 KBdewalt
#136 2825860-nr-bot.txt2.14 KBneeds-review-queue-bot
#135 core-notice_in_numeric_filter-2825860-135.patch5.25 KBdewalt
#134 core-notice_in_numeric_filter-2825860-134.patch4.86 KBdewalt
#131 core-notice_in_numeric_filter-2825860-131.patch2.03 KBdewalt
#130 interdiff_129_130.txt436 bytesericgsmith
#130 2825860-130.patch8.57 KBericgsmith
#129 interdiff_116_129.txt613 bytesericgsmith
#129 2825860-129.patch8.07 KBericgsmith
#122 interdiff-2825860-116_to_121.txt755 bytesjoseph.olstad
#121 2825860-121.patch8.08 KBjoseph.olstad
#116 interdiff-2825860-111_to_116.txt1.38 KBjoseph.olstad
#116 2825860-116.patch8.07 KBjoseph.olstad
#115 interdiff_111-115.txt1.5 KBRatan Priya
#115 2825860-115.patch8.17 KBRatan Priya
#112 views.view_.content.yml17.75 KBmatroskeen
#111 2825860-111.patch7.73 KBmatroskeen
#107 Screenshot 2022-07-23 at 1.38.11 PM.png142.04 KBameymudras
#107 Screenshot 2022-07-23 at 1.37.11 PM.png208.14 KBameymudras
#105 2825860-105.patch7.77 KBbobooon
#103 2825860-103.patch7.73 KBmatroskeen
#99 2825860_97-99.txt2.81 KBmatroskeen
#99 2825860-99.patch7.76 KBmatroskeen
#97 2825860-97.patch7.86 KBmatroskeen
#97 2825860-97-tests_only.patch6.72 KBmatroskeen
#86 2825860-86.patch4.1 KBmatroskeen
#86 2825860-86-test-only.patch3.15 KBmatroskeen
#82 2825860-82.patch3.23 KBmatroskeen
#82 2825860-82-test-only.patch2.28 KBmatroskeen
#80 2825860-80-test-only.patch1.69 KBmstrelan
#79 views.view_.content.yml18.15 KBmstrelan
#64 1.1Screenshot at Oct 06 16-22-16.png297.91 KBvindesh
#60 2825860-exposed-filter-notice-60.patch972 bytesvetal4ik
#56 2825860-exposed-filter-notice-56.patch3.26 KBryankavalsky
#54 Screen Shot 2021-03-30 at 11.28.00 AM.png327.04 KBbanoodle
#53 pages_filtered.jpg74.09 KBkndr
#53 pages_default.jpg75.79 KBkndr
#53 filter_settings.jpg78.57 KBkndr
#53 view_settings.jpg138.69 KBkndr
#53 status_report.jpg179.32 KBkndr
#48 2825860-48.patch2.49 KBrajneeshb
#38 2825860-exposed-filter-notice-38.patch2.48 KBdpi
#33 exposed-filter-notice-2825860-33.patch2.48 KBcodigovision
#26 exposed-filter-notice-2825860-25.patch1.58 KBjagermonster
#24 exposed-filter-notice-2825860-24.patch1.31 KBjwilson3
#22 exposed-filter-notice-2825860-22.patch662 bytesthomjjames
#20 study_mode.yml1.24 KBacbramley
#15 exposed-filter-notice-2825860-14.patch1.18 KBaby v a
#13 interdiff-2825860-12-13.txt788 bytesaby v a
#12 exposed-filter-notice-2825860-11.patch1.17 KBhygglo
#10 exposed-filter-notice-2825860-10.patch662 bytesrob230
#4 2825860--exposed-filter-notice.patch669 bytesdpolant
#2 2500313--views-get-paging-support.patch7.09 KBdpolant

Issue fork drupal-2825860

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

dpolant created an issue. See original summary.

dpolant’s picture

StatusFileSize
new7.09 KB

Attached a simple patch that looks at whether the "value" key is set.

dpolant’s picture

dpolant’s picture

StatusFileSize
new669 bytes

Sorry that was the wrong patch. Here is the correct one.

sagesolutions’s picture

Thank you, the patch in #4 worked for me.

kikoalonsob’s picture

Status: Active » Needs review

Don't forget to mark the issue as «needs review» to process tests.

lendude’s picture

Status: Needs review » Needs work

Add an exposed grouped filter on Content Type A's ER field to Content Type B

Are you using the patch in #2369119: Fatal error when trying to save a View with grouped filters using other than string values to do this?

It feels like this is fixing a symptom, not the actual bug. Why is 'value' not set, that is the part I don't get.

We would also need a test for this.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sagesolutions’s picture

@lendude, Yes I also applied the patch from #2369119.

rob230’s picture

StatusFileSize
new662 bytes

I'm getting this bug. I have an exposed filter for a taxonomy which can accept multiple values and is optional. The $input array has this:

'my_field' => array(0)

As such, the following code sees that $value is already an array, and $value ends up as array(0):

if (!empty($this->options['expose']['identifier'])) {
  $value = &$input[$this->options['expose']['identifier']];
  if (!is_array($value)) {
    $value = [
      'value' => $value,
    ];
  }
}

which means testing $value['value'] gives a notice:

if ($value['value'] === '') {
  return FALSE;
}

I've uploaded my suggested fix, which I think makes more sense than the previous patch, because it ensures the value is in the format expected.

rob230’s picture

I found my patch above breaks for filters using "between", because instead of 'value' they use 'min' and 'max'.

Best to use #4.

I agree with Lendude though, it seems like something is not right here. Perhaps someone with more knowledge of Views in Drupal 8 could investigate.

hygglo’s picture

StatusFileSize
new1.17 KB

Adding a check for min and max values

aby v a’s picture

StatusFileSize
new788 bytes

Hi,
I have also faced this issue. Thanks for the patch and some coding standard has been applied.

aby v a’s picture

Status: Needs work » Needs review
aby v a’s picture

StatusFileSize
new1.18 KB

The last submitted patch, 10: exposed-filter-notice-2825860-10.patch, failed testing. View results

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

maxmendez’s picture

The last patch work in my case.

acbramley’s picture

StatusFileSize
new1.24 KB

I'm getting this when using a grouped SearchApiString field (which extends SearchApiNumeric which extends NumericFilter).

NumericFilter::acceptExposedInput is called twice per page load, once on form submission and once when rerendering the view. During the form submission call, I can see that $value is an array that is the same length as the number of grouped filters (in my case 2). The keys of the array are 0 and 1 and the values for those keys are either the integer 0 (representing the filter not being applied), or if the filter has been submitted a string value for the key. E.g [0 => "0", 1 => 0] for the first filter being applied.

This seems to get translated at render time as then $value will be an array with the key "value" that equals the actual value that the grouped filter has applied. In my case "Full time" or "Part time".

I've attached the sample of my views field config.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

thomjjames’s picture

StatusFileSize
new662 bytes

Patches attached didn't work for me on a grouped numeric field using the search API.

Attaching a modified patch which did work although not sure it covers all implications.

Thanks
Tom

jwilson3’s picture

How is patch #22 better than #14? Afaict, they have the same feature, but #14 has more.

jwilson3’s picture

StatusFileSize
new1.31 KB

Re-roll of #14 that applies to 8.7.x

jagermonster’s picture

I was still receiving the Notice: Undefined index: value in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput() (line 399 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).
Just required one more !isset check on case 1 of NumericFilter

jagermonster’s picture

StatusFileSize
new1.58 KB
lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Still needs tests, still needs proof that this isn't just masking the underlying problem.

attheshow’s picture

Patch in #26 is working for us.

trevorbradley’s picture

Another +1 for Patch #26.

ktch_my’s picture

8.8.1 patched with #26
Notice Error gone, but the grouped filter doesn't work anymore. All options returns same results.

extexan’s picture

After applying the #26 patch to D8.8, I too am seeing the same thing that @ktch_my reported - all options, same results - which is to say, the results aren't filtered at all.

I think @Lendude's observation is spot-on. The patch is masking the underlying problem. The changes in patch #26 will make the method(s) return FALSE instead of getting the error - and FALSE indicates no filter was selected.

I'm trying to debug it, but if anyone has time before I find the problem, it might be worthwhile to see what changed in those two classes between 8.6 and 8.8. That might point us in the right direction.

extexan’s picture

I've identified how the patch "masked" the underlying problem.

This code, just before the patched code in acceptExposedInput() in /core/modules/views/src/Plugin/views/filter/NumericFilter.php, never sets $value['value'] because it is using the wrong "identifier".

    // rewrite the input value so that it's in the correct format so that
    // the parent gets the right data.
    if (!empty($this->options['expose']['identifier'])) {
      $value = &$input[$this->options['expose']['identifier']];
      if (!is_array($value)) {
        $value = [
          'value' => $value,
        ];
      }
    }

So, with no $value['value'] defined, the patched code returns FALSE - i.e. no filter selected.

The problem seems to be upstream from this function (method). The identifier it is getting is the original default identifier - which is the full field name. We have overridden all identifiers in all our views. In this case, we used "whse_in" - but the above code is using "field_warehouse_in_date_value". I verified that by changing the identifier in the view back to the default value and the grouped filter worked (in D8.8).

I will keep looking to see if I can find where the actual issue is, but if anyone else finds it before I do, please post back here. At least now we have a work-around.

codigovision’s picture

Version: 8.6.x-dev » 8.8.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.48 KB

Adding a patch that contains everything from #26 and a fix for grouped filters. I just updated acceptExposedInput in NumericFilter to use the same group logic as the FilterPluginBase.

tanashin-kishimoto’s picture

Patch #33 work for me on 8.8.1.

ktch_my’s picture

Patch #33 on 8.8.1 works for me.

JFH - 3DX internet’s picture

Patch #33 on 8.8.2 works for me.

dcam’s picture

Adding the related issue that was recently backported to 8.8.x.

dpi’s picture

StatusFileSize
new2.48 KB

Reroll after #2824935: Fix Squiz.ControlStructures.SwitchDeclaration coding standard

This patch is compatible with 9.0.0

dpi’s picture

Version: 8.8.x-dev » 9.1.x-dev
lendude’s picture

Status: Needs review » Needs work

Back to NW for the test

kyberman’s picture

Thank you @CodigoVision, the patch #33 works nicely with 8.8.8.

kedxu’s picture

Thanks all. #38 seems to be working Drupal 9.0.2 & PHP 7.3

rp7’s picture

#38 works for me with D8.9. Thanks everyone!

belba’s picture

Confirm that the patch is working on 8.9.5
Great job!

liquidcms’s picture

Fails to apply to 8.8.4

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ryankavalsky’s picture

For me, #38 mostly worked for me on 8.9.7. I also needed to apply the same logic on lines 251 and 257 of NumericFilter.php.

before: $this->value['value']
after: isset($this->value['value']) ? $this->value['value'] : ""

rajneeshb’s picture

Status: Needs work » Needs review
StatusFileSize
new2.49 KB

Re-roll of #38 that applies to 9.2.x

extexan’s picture

Any chance this could be merged into the latest D8 version? I just updated to D8.9.9 and I still have to re-apply the patch.

Seems like it passed RTBC a while back.

lendude’s picture

Status: Needs review » Needs work

Still needs a test unfortunately

kndr’s picture

I can't reproduce the bug on 9.2.x. These are steps I made:

  1. Install a fresh Drupal site
  2. Set $config['system.logging']['error_level'] = 'verbose'; in a settings.php file
  3. Go to 'Manage fields' for a 'Basic page' content type at admin/structure/types/manage/page/fields
  4. Press 'Add a new field ' button
  5. Choose 'Reference >Content' in a 'Add a new field' select box
  6. Set 'article' in a 'Label' text field
  7. Press 'Save and continue' button
  8. Set 'Limited: 1' in a 'Allowed number of values'
  9. Press 'Save field settings' button
  10. Check 'Article' in a 'REFERENCE TYPE' section
  11. Press 'Save settings' button
  12. Add the first 'Article' - set its title to 'Article 1'
  13. Add the second 'Article' - set its title to 'Article 2'
  14. Add the first 'Basic page' - set its title to 'Page 1'
  15. Set 'Article 1' in a field 'article' of 'Page 1'
  16. Add the second 'Basic page' - set its title to 'Page 2'
  17. Set 'Article 2' in a field 'article' of 'Page 2'
  18. Add a new view at admin/structure/views/add
  19. Set 'Pages' in a 'View name'
  20. Set 'Content' + 'Basic page' in a 'View settings' section
  21. Check 'Create a page' in a 'Page settings' section
  22. Press 'Save and edit' button
  23. Press 'Add' button at 'Filter criteria' section
  24. Search for 'field_article'
  25. Check 'field_article' and press 'Add and configure filter criteria' button
  26. Check 'Expose this filter to visitors, to allow them to change it'
  27. Select 'Grouped filters' radio button
  28. Set 'field_article_target_id_XXX' in a 'Filter identifier' text field
  29. Set 'Article 1' in a 'Label column' and set 1 in a 'Value' column of the first row
  30. Set 'Article 2' in a 'Label column' and set 2 in a 'Value' column of the second row
  31. Press 'Apply' button
  32. The messages 'The view Pages has been saved' and 'You have unsaved changes' are displayed.
  33. Press 'Save' button
  34. The message 'The view Pages has been saved.' is displayed
  35. Go to a view page at the /pages address
  36. There are a list with four elements: "Page 2", "Page 1", "Article 2", "Article 1"
  37. Choose 'Article 1' option in a 'article (field_article)' select box
  38. Press 'Apply'
  39. 'Page 1' is displayed as expected
  40. There is neither error nor notice

Did I miss something?

extexan’s picture

@kndr, perhaps check the mods in the patch for this issue to see if they have been done in 9.2.x-dev, but not yet merged into 8.9.x-dev.

kndr’s picture

StatusFileSize
new179.32 KB
new138.69 KB
new78.57 KB
new75.79 KB
new74.09 KB

@ExTexan I can't reproduce the error on a fresh installation 8.9.12-dev too. I followed the steps I mentioned at #51 with no effect. I still miss something in my steps or the bug doesn't exist any longer.

Status report:

status report

View settings:

view settings

Filter settings:

filter settings

Page view at /pages:

pages default

Page view at /pages?field_article_target_id_XXX=1:

pages filtered

banoodle’s picture

StatusFileSize
new327.04 KB

I'm on 8.9.13 and confirm this problem still happens. In this case it is happening with the report view provided by the Linkchecker module (1.0.0-alpha1)

Screenshot of min notice

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ryankavalsky’s picture

StatusFileSize
new3.26 KB

I've re-rolled my patch to include the changes in #38 and my comments in #47. Applies to 8.9.15.

naresh_bavaskar’s picture

I am not able to reproduce the warning described in the issue,
followed same steps as @kndr did, in the #15 comment

kim.pepper’s picture

Issue tags: +#pnx-sprint
petr illek’s picture

Hi,
I just got this issue with Drupal 9.2, Grouped filters for a date field with BEF. The thing which breaks it for me is when I change the default `group-info-identifier` (Filter Identifier) value which is something like `field_date` to something else.
The patch in #48 fixed it for me.

vetal4ik’s picture

StatusFileSize
new972 bytes

I reproduced this bug by using #59 steps.

The reason for this bug is that we have two different identifiers for exposed and grouped filters. (If a filter is exposed and grouped, handler uses `$this->options['group_info']['identifier']` as identifier, if the filter is just exposed but isn't grouped `$this->options['exposed']['identifier']`);
The `NumericFilter` handler ignores this case, so I just fixed it.
Another question is why we need two identifiers for grouped and exposed handlers.

vetal4ik’s picture

Status: Needs work » Needs review
fathima.asmat’s picture

I can confirm #61 works for me. Thanks for the patch.

Status: Needs review » Needs work

The last submitted patch, 60: 2825860-exposed-filter-notice-60.patch, failed testing. View results

vindesh’s picture

StatusFileSize
new297.91 KB

Getting similar error in Views: Drupal 8.9.14

Notice: Undefined index: empty in Drupal\views\Plugin\views\filter\NumericFilter->adminSummary() (line 390 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).
Drupal\views\Plugin\views\filter\NumericFilter->adminSummary() (Line: 1100)

Solution is working for me: (line 390 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).
Remove or comment below line and add new line
---//$output = $options[$this->operator];

Add this line
+++$output = empty($options[$this->operator])?'':$options[$this->operator];

leo pitt’s picture

On 9.2.8, I was getting the following error:

`Notice: Undefined index: min in Drupal\views\Plugin\views\filter\Date->acceptExposedInput() (line 160 of /var/www/web/core/modules/views/src/Plugin/views/filter/Date.php)`

Patch at #60 did not work for me.
Patch at #48 did work.

inge_dt’s picture

I have a grouped filter (uses "in between") that gave me this error, on Drupal 9.2.8 - patch #48 worked for me.

siegrist’s picture

I have the same behaviour as #66. The input array only holds an empty array for the key in question. Not sure why the info is missing though...
#48 works for me too.

dystopianblue’s picture

Was getting `Notice: Undefined index: value in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput()` on line 428 of NumericFilter.php. #48 fixed it for me as well.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

luli_schnauzer’s picture

I am applying patch #48 for 9.2.9 but still it is not working for me. The reason I think is that I set my grouped (and exposed) filter as multiple. When selected as single select, it works fine for me.

hswong3i made their first commit to this issue’s fork.

hswong3i’s picture

Status: Needs work » Needs review

PR created from #60

matroskeen’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs steps to reproduce

I wanted to take care of tests, but I'm not able to reproduce this issue following the steps in the issue summary.
Can anyone update the steps, please? I believe I'm missing something minor, so please share as many details as you can.

Please also include a full notice report, so we can see which line is affected.
Thanks!

guillaumeg’s picture

Same issue here, patch #56 (https://www.drupal.org/project/drupal/issues/2825860#comment-14096179) fixes the issue, the patches after don't.

tlwatson’s picture

Was experiencing a similar issue to https://www.drupal.org/project/drupal/issues/3105759 .
Patch #48 worked for me on Drupal 9.3.3

omkar_yewale’s picture

I was experiencing a similar issue on Drupal 9.3.5, Patch #48, and (#53)
These two patches worked for me.

mstrelan’s picture

Issue summary: View changes
Issue tags: -Needs steps to reproduce

Since PHP 8 this now results in a fatal TypeError. I've managed to replicate this in a vanilla installation and have updated the issue summary with steps to reproduce.

mstrelan’s picture

StatusFileSize
new18.15 KB

I've also attached a config export of the view that results in the fatal error.

mstrelan’s picture

StatusFileSize
new1.69 KB

Here's a failing test. It could use some work and could probably be a Kernel test, but it should at least demonstrate the issue.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

matroskeen’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.28 KB
new3.23 KB

@mstrelan thanks, this is great! It helped me to discover that the catch is in using another identifier for the grouped filter.
I agree with the proposed fix in the merge request, so I'm attaching a patch with the MR contents, so we can run tests for multiple branches.

Speaking of tests, it might be confusing but we have multiple test classes for Date filter, that's why I opened: #3252479: Combine views date filter test classes.
We also already have a test for exposed grouped date filters, so I just needed to edit a couple of lines to get the same failure. You can check a test-only patch attached here.

I'm also changing the target version to 10.0.x, but we'll try running tests on all active versions.

Status: Needs review » Needs work

The last submitted patch, 82: 2825860-82.patch, failed testing. View results

matroskeen’s picture

Status: Needs work » Needs review

The patch was failing because of some phpstan issues in the main branches.

lendude’s picture

The fix looks great and good to see test coverage. But #82 is modifying existing test coverage from a pass to a fail, so are we losing test coverage there or was that testing something in the wrong way to give a false positive?

matroskeen’s picture

StatusFileSize
new3.15 KB
new4.1 KB

Before that, we were testing where the "exposed" identifier matches the "group" identifier. Those identifiers are stored as different keys and might be different, which is also often confusing.

Anyway, I think it won't hurt to test both scenarios (default identifier + modified), so I went ahead and expanded the test a bit.

The last submitted patch, 86: 2825860-86-test-only.patch, failed testing. View results

lendude’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

@Matroskeen nice, thanks for the explanation and the extended test coverage, looks great now.

neclimdul made their first commit to this issue’s fork.

neclimdul’s picture

Status: Reviewed & tested by the community » Needs review

Not a fan of hacking that functional test since it can't really test all the options without being super expensive. Here's an option with unit tests.

Writing the test exposed that the current patch can trigger an "PHP Warning: Undefined variable $value" with some (invalid) configurations.

Updated the merge request with the changes because that's where I was working.

matroskeen’s picture

@neclimdul, if you would look at Drupal\views\ViewExecutable::_build($key), you'll see that FilterPluginBase::acceptExposedInput() is called after FilterPluginBase::convertExposedInput(), FilterPluginBase::storeGroupInput() and even FilterPluginBase::groupMultipleExposedInput() if multiple selection is enabled.

I think this order is important. At least, FilterPluginBase::convertExposedInput() modifies group_info plugin property, which is later used in FilterPluginBase::acceptExposedInput().

Furthermore, for some plugins like \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid, you'll also need to call ::validateExposed() because it sets $this->validated_exposed_input property, which is expected by \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::acceptExposedInput().

I love the idea to have unit tests for things like that, but those Views filters are complicated...

neclimdul’s picture

So, first, sorry I didn't get this posted before you started work on your tests and this got RTBC'd. I had it mostly written Wednesday last week but I got sick and only just got back to it and was like "Woah! There's a bug, this isn't RTBC!" I'd actually planned on filling out the unit test a bit more before posting it if possible but wanted to get it into the discussion quickly since y'all where moving fast :)

As for the review, I'll agree these methods are super complicated and a mess. There's no clear interface so the boundaries of what should happen and what sort of per-conditions a method has are not clear. Also, the array of values as an interface makes things complicated. Its a hard thing to write tests for but honestly that just means the CRAP score is probably pretty high and its even _more_ important to test each unit individually.

Looking at the code you mentioned, I don't think it changes the approach to testing this.

  • It looks like the functions you mention also fails to handle the tested options and would also emit warnings. Also, if I'm reading them correctly they pass through for that case so if they didn't, they'd still trigger the exact code being tested in the unit test.
  • Those methods are inherited so more complexity. We're inheriting unrelated bug fixes to a base class that could break expected pre-conditions. More reason to not trust their behavior and test an isolated unit.
  • Similarly, even if those methods fixed it right now, the _point_ of unit testing it is that a bug fix to those methods could have the side effect of passing a different set of values to this method. This method has to be bug free by itself with given inputs. The provided test tries to do that with "reasonable" values still relying on the default processing in init to set a baseline.
  • Its a plugin and the point is to be unit testable. And the point of unit testing is to test the smallest testable code. So if possible a single test should be testing the inputs/outputs of a single method on its own.

Additional note, its not one or the other testing. Your functional test might still be useful in a different way since it's troubling that there doesn't seem to be a test that the grouped numeric filter actually interacts with the exposed form correctly. That's a pretty important _function_ to test as a whole.

matroskeen’s picture

Thanks for the explanation! I interpreted the suggested unit test as a replacement for the functional testing, so I was skeptical. We can definitely keep both, but the question is: should we add both tests in the same issue? I would be happy to work on a new META issue to add unit tests for other plugins and potentially refactor the plugins (there is a big room for improvement there). Looking forward to your suggestions.

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

Agree with #93, it would be great to spin the unit tests into a separate issue and churn there.
Back to RTBC for #86

neclimdul’s picture

Status: Reviewed & tested by the community » Needs review

no, there's a bug in that patch. Also, I think the suggestion was to add a meta for _other_ plugins. The suggestion was that maybe we add both and I think that's a good approach.

acbramley’s picture

Status: Needs review » Needs work

Ok, it's NW then because the MR doesn't contain any of the tests from #86.

matroskeen’s picture

Status: Needs work » Needs review
StatusFileSize
new6.72 KB
new7.86 KB

Here is a patch that combines the MR and the patch in #86.

The last submitted patch, 97: 2825860-97-tests_only.patch, failed testing. View results

matroskeen’s picture

StatusFileSize
new7.76 KB
new2.81 KB

Making some minor changes to the latest patch:

  1. Removed helper getView method - we use it in one place and can always add back where there is a need (I think adding new method is easier than moving existing ones);
  2. Used getStringTranslationStub() method to inject the translation plugin;
  3. Added comments, return type hints, and other small changes;
lendude’s picture

+++ b/core/modules/views/tests/src/Unit/Plugin/views/filter/NumericFilterTest.php
@@ -0,0 +1,117 @@
+        // Missing value is ok?
+        TRUE,

Really minor knit, but we don't want to leave a comment like this, that is just going to confuse in the future. So we are either ok with this and then the comment should say that, or we are not ok with this and we need to open a follow up to address this and link to that.
I think we are ok with this?

thirstysix’s picture

+RTBC
#99 works fine with D9.4.1

sseto’s picture

#99 works fine with D9.4.2 and PHP8.1.8

matroskeen’s picture

StatusFileSize
new7.73 KB

@lendude, yeah I think we are okay with that (I don't see a need to disagree with FilterPluginBase::acceptExposedInput()).
I just removed that comment, so there is no interdiff attached.

bobooon’s picture

+RTBC #99

bobooon’s picture

StatusFileSize
new7.77 KB

Error still thrown with #99 and #103. Problem is $input assumes the value key exists if the array is empty.

-      if (!is_array($value)) {
+      if (!is_array($value) || !$value) {
bobooon’s picture

Status: Needs review » Needs work

If the grouped filter has "Allow multiple selections" enabled the $value = &$input[$this->options[$key]['identifier']]; is either an empty array or an array of the grouping IDs. Last patch only resolves the error in this scenario when no filter is selected. Still occurs the moment one or more grouped filters are selected.

ameymudras’s picture

Using Drupal 10.0.x & php 8.1 I followed the steps mentioned below which are included in the summary:

  1. Install Drupal standard profile
  2. Edit the default Content view at /admin/structure/views/view/content
  3. Add a "Changed" filter
  4. Select "Expose this filter to visitors, to allow them to change it"
  5. Select "Grouped filters"
  6. Change the "Filter identifier" to "date"
  7. Set the Grouping 1 label to "Last week", operator to "Is greater than", value type to "An offset from ..." and value "-7 days"
  8. Press Apply and then Save
  9. Navigate to /admin/content
  10. Set the "Changed" filter to "Last week" and press "Filter".

But i don't see any warning / notice as mentioned.

mstrelan’s picture

I'm confused, we had a failing test that reproduces the issue and a fix for it as well. If there is some other issue that needs steps to reproduce then let's log a separate issue for it.

bobooon’s picture

Status: Needs work » Needs review

I assumed this issue covered any filter using the numeric handler. #99 and #103 indeed fix the error when grouping dates. Other field types using the numeric handler may or may not be working as expected with those patches.

In my particular use case, the exposed filter is a state machine (https://www.drupal.org/project/state_machine) field type with several grouped filters using the "Is equal to" operator. Optional and allow multiple selections is checked. With the patch in #99 or #103 applied, an identical PHP notice is thrown both without and with exposed input applied.

Anyways, I won't hijack the original bug smash. Moving back to the needs review status.

mstrelan’s picture

Apologies @robphillips I missed your comments above. Perhaps this should all be fixed together after all.

matroskeen’s picture

Issue summary: View changes
Issue tags: -Needs steps to reproduce
StatusFileSize
new7.73 KB

Re #107:
I verified the steps again - it's reproducible. I checked your screenshot and it seems that #6 step is missing - "changed" Filter identifier should be changed to something else, for example, "date". I'm attaching yml file with the configured view. You can import it to your website and check /admin/content page.

Re #109-110:
This issue is targeting a case when the numeric (or any child filter) is exposed, grouped, and has a non-default "Filter identifier" value. @robphillips your case also requires "Allow multiple selections" to be selected, which is already a bit different. We're very close to the RTBC/commit here, so expanding the scope will require changes to the automated tests and another round of reviews. I suggest the following plan:
1) Restore the last patch to #103 version (doing it here);
2) Create a follow-up to target an issue reported by @robphillips;
3) If it depends on this one, you can add [PP-1] at the beginning of the title and mark it postponed;

matroskeen’s picture

StatusFileSize
new17.75 KB

(now really attaching a yml file for the test)

lendude’s picture

Status: Needs review » Reviewed & tested by the community

I with #111 agree on keeping the scope as it is. Please open a follow-up issue for the other scenario that might still be broken.

Assuming this comes back green, moving to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php
@@ -404,16 +404,21 @@ public function acceptExposedInput($input) {
-    if (!empty($this->options['expose']['identifier'])) {
-      $value = &$input[$this->options['expose']['identifier']];
+    $key = $this->isAGroup() ? 'group_info' : 'expose';
+    if (!empty($this->options[$key]['identifier'])) {
+      $value = &$input[$this->options[$key]['identifier']];
       if (!is_array($value)) {
         $value = [
           'value' => $value,
         ];
       }
     }
+    else {
+      // Invalid identifier configuration. Value can't be resolved.
+      return FALSE;
+    }

Given we're doing an early return here I think we should change the method to be....

    // Rewrite the input value so that it's in the correct format so that
    // the parent gets the right data.
    $key = $this->isAGroup() ? 'group_info' : 'expose';
    if (empty($this->options[$key]['identifier'])) {
      // Invalid identifier configuration. Value can't be resolved.
      return FALSE;
    }
    $value = &$input[$this->options[$key]['identifier']];
    if (!is_array($value)) {
      $value = [
        'value' => $value,
      ];
    }

Also later on in the code we do

if (empty($this->options['expose']['required'])) {

Should this also be changed to if (empty($this->options[$key]['required'])) {?

Ratan Priya’s picture

Status: Needs work » Needs review
StatusFileSize
new8.17 KB
new1.5 KB

@alexpott,
Made changes as per comment #114.
Needs review.

joseph.olstad’s picture

StatusFileSize
new8.07 KB
new1.38 KB

@Ratan Priya, I believe those were not the exact changes requested.

see interdiff and new patch.

alexpott’s picture

Thanks for rolling the new patch.

+++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php
@@ -407,22 +407,20 @@ public function acceptExposedInput($input) {
-    if (empty($this->options['expose']['required'])) {
+    if (empty($this->options[$key]['required'])) {

I don't know if this change is correct... It'd be great to get input from a view maintainer... pinging @Lendude!

joseph.olstad’s picture

#115 failed on Drupal\Tests\views\Kernel\Handler\FilterNumericTest
#116 might also fail on the same one due to the $key change, hard to say

***EDIT*** #116 passed Drupal\Tests\views\Kernel\Handler\FilterNumericTest 18 passes

The last submitted patch, 115: 2825860-115.patch, failed testing. View results

lendude’s picture

Priority: Normal » Major
Status: Needs review » Needs work
+++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php
@@ -404,20 +404,23 @@ public function acceptExposedInput($input) {
+    if (empty($this->options[$key]['required'])) {

@alexpott well spotted, that change is indeed not correct and needs to be reverted.

'expose' uses the 'required' key while the 'group_info' uses the 'optional' key

So if I'm seeing this correctly, currently this logic always triggers in grouped filters since 'expose''required' will always be empty in that case. I suggest we open a follow up for that? The logic added here doesn't make that any more broken than it already is right?

Also bumping to major since, as @mstrelan pointed out in #78, this leads to a fatal error on PHP8

joseph.olstad’s picture

Status: Needs work » Needs review
StatusFileSize
new8.08 KB

reroll

joseph.olstad’s picture

StatusFileSize
new755 bytes

here's the interdiff

Status: Needs review » Needs work

The last submitted patch, 121: 2825860-121.patch, failed testing. View results

joseph.olstad’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

patch 116 is the good one, ignore 121

joseph.olstad’s picture

Patch 116 is clean on 9.3.x, 9.4.x, 9.5.x, 10.x and 10.1.x

joseph.olstad’s picture

patch number 116 passes on 10.1.x, 10.x, 9.5.x, 9.4.x and 9.3.x on PHP 8.1

didebru’s picture

Patch 116 didn't fix the issue I have:
TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\filter\NumericFilter->valueForm() (line 250 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).
Drupal\views\Plugin\views\filter\NumericFilter->valueForm(Array, Object) (Line: 939)
Drupal\views\Plugin\views\filter\FilterPluginBase->buildExposedForm(Array, Object) (Line: 111)
Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 134)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1240)
Drupal\views\ViewExecutable->build() (Line: 392)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 196)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1657)
Drupal\views\ViewExecutable->executeDisplay('page_1', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 164)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

ericgsmith’s picture

Version: 10.0.x-dev » 10.1.x-dev
StatusFileSize
new8.07 KB
new613 bytes

Adding a new patch as #116 does not address the feedback in #120, and the patch #121 reverts the wrong line.

I is not clear if #128 is related to this patch as I was unable to reproduce this error - but given the comment includes with "didn't fix the issue I have" implies this issue existed before the patch and so I think it is unrelated. @DiDebru can you please confirm?

ericgsmith’s picture

StatusFileSize
new8.57 KB
new436 bytes

Looks like we can remove the expected errors from the baseline too.

Queued tests for 129 on 9.5 as this patch will not apply to 9.5 - and will check 10.1 / 10.0 on this patch

dewalt’s picture

I've made some investigation and I like to propose other solution.

Why it happens?

The warning is triggered in NumericFilter::acceptExposedInput() and it called twice. With grouped filter first time there is just an integer (e.g. 1) in input that triggers the warning, the second time input gets expected input as array with keys ['value', 'type', 'min', 'max']. It looks strange as it is expected to have the same input on each call.

First call in ViewExposedForm::submitForm() that triggers warning:

    // Form input keys that will not be included in $view->exposed_raw_data.
    $exclude = ['submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'];
    $values = $form_state->getValues();
    foreach (['field', 'filter'] as $type) {
      /** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */
      $handlers = &$form_state->get('view')->$type;
      foreach ($handlers as $key => $info) {
        if ($handlers[$key]->acceptExposedInput($values)) {
          $handlers[$key]->submitExposed($form, $form_state);
        }
        else {
          // The input from the form did not validate, exclude it from the
          // stored raw data.
          $exclude[] = $key;
        }
      }
    }

Second time in ViewExecutable:_build() without warning

    $handlers = &$this->$key;
    foreach ($handlers as $id => $data) {

      if (!empty($handlers[$id]) && is_object($handlers[$id])) {
        $multiple_exposed_input = [0 => NULL];
        if ($handlers[$id]->multipleExposedInput()) {
          $multiple_exposed_input = $handlers[$id]->groupMultipleExposedInput($this->exposed_data);
        }
        foreach ($multiple_exposed_input as $group_id) {
          // Give this handler access to the exposed filter input.
          if (!empty($this->exposed_data)) {
            if ($handlers[$id]->isAGroup()) {
              $converted = $handlers[$id]->convertExposedInput($this->exposed_data, $group_id);
              $handlers[$id]->storeGroupInput($this->exposed_data, $converted);
              if (!$converted) {
                continue;
              }
            }
            $rc = $handlers[$id]->acceptExposedInput($this->exposed_data);
            $handlers[$id]->storeExposedInput($this->exposed_data, $rc);
            if (!$rc) {
              continue;
            }
          }
          $handlers[$id]->setRelationship();
          $handlers[$id]->query($this->display_handler->useGroupBy());
        }
      }
    }

So for me there are two questions:

  • Why NumericFilter::acceptExposedInput() is called twice?
  • Why NumericFilter::convertExposedInput() that converts group input to expected format is missed in first case?(By the way I've tried to add it to first case, but it breaks the view execution)

One more strange thing found

Also I pay attention to broken $exclude variable, it declared twice in ViewExposedForm::submitForm() and isn't useful in first case.

    // Form input keys that will not be included in $view->exposed_raw_data.
    $exclude = ['submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'];
    foreach (['field', 'filter'] as $type) {
          // ... Some code miss ...
          $exclude[] = $key;
    }

    // Rewrites upper results here.
    $exclude = ['submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'];
    foreach ($values as $key => $value) {
      // Used last assignment only.
      if (!empty($key) && !in_array($key, $exclude)) {
        // ... Some code miss ...
      }
    }

Changes history

I've go to look for this changes in history and found that all this things above were added in this issue #2651102 (patch). The patch adds checkbox processing to form values and inside NumericFilter::acceptExposedInput() and non-working first $exclude assignment. The code before the patch:

    foreach (array('field', 'filter') as $type) {
      /** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */
      $handlers = &$form_state->get('view')->$type;
      foreach ($handlers as $key => $info) {
        $handlers[$key]->submitExposed($form, $form_state);
      }
    }

Looks like NumericFilter::acceptExposedInput() was used to process checkboxes before call NumericFilter::submitExposed(), but:

  • NumericFilter doesn't use ::submitExposed() method, it inherits empty functionality
  • No core views filter has the method
  • No Search API views filter has the method
  • If custom module implements ::submitExposed(), it could care about checkbox processing inside
  • $exclude improvements aren't working

Proposal

I propose to revert a part of issue #2651102 described above, that causes warning and looks like doesn't have effective changes. @catch, @mikeker, welcome to comment!

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Can confirm this issue and that the patch addresses it.
It will need test coverage though.

mstrelan’s picture

FWIW there are tests in the patches up until #131. I haven't really looked at the new approach but perhaps if we had an updated patch with the test from #130 and the fix from #131 we can confirm if this fixes the same issue.

dewalt’s picture

Existing tests changed to handle the notice. One more notice found when group identifier doesn't match to simple exposed one and fixed.

dewalt’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new5.25 KB

One more small improvement to prevent possible notices if identifier is empty (looks it could happen on wrong config only), but anyway there is no sense to make additional check if parent::acceptExposedInput() returns FALSE.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.14 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

dewalt’s picture

Status: Needs work » Needs review
StatusFileSize
new5.25 KB

Fixed CSpell issues, but phpcs warning isn't happens locally and surprises me at all, the variable isn't unused.

FILE: ...l10/core/modules/views/src/Plugin/views/filter/NumericFilter.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
411 | WARNING | Unused variable $value.
----------------------------------------------------------------------

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.04 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

akram khan’s picture

StatusFileSize
new13.17 KB
new8.65 KB

Added Updated patch and fixed CCF #137

akram khan’s picture

Status: Needs work » Needs review
dewalt’s picture

@Akram, as far as I understand renaming "_test*" methods to "test*" means that it runs by phpunit engine itself, I afraid with the changes these methods called twice now, by phpunit engine and from ::testDateFilter() directrly.

acbramley’s picture

Status: Needs review » Needs work

NW on #141

xurizaemon’s picture

Status: Needs work » Needs review
StatusFileSize
new660 bytes
new12.96 KB

Took a quick look at #drupalsouth code sprint. Looks like function testDateFilter() can be dropped then.

smustgrave’s picture

Status: Needs review » Needs work

Took a brief look and seems there are some out of scope changes that were probably introduced in #139

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dewalt’s picture

IMHO, I don't support an idea to beatify all the file (not the changed lines only), I think doc-comments should be added in a scope of other issue, but not in a bug. By the example from previous patches I've just add `$value = NULL;` to pass PHPCS, rebased to 11.x branch and no more changed from #137.

P.S. by the way PHPStorm not highlights the variable as unused(

dewalt’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed the problem in the issue summary following the steps.
Note doesn't matter the identifier name, tried a few different ones but always got the error.

Applying the patch #146 solved the issue and see it has test coverage as well.

Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 146: core-notice_in_numeric_filter-2825860-146.patch, failed testing. View results

vasike’s picture

Status: Needs work » Reviewed & tested by the community

it seems that patch actually passes.

back to RTBC

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Sometime between #130 and #131 this patch changed dramatically.

Can we elaborate why?

We had subsystem maintainer signoff on the approach in ##13 (see #113 and #120)

The changes to remove all the special keys like form build ID definitely feel wrong to me.

Can we go back to #130 and can those with the new approach elaborate why it isn't suitable?

neclimdul’s picture

Where did the unit test go? It was exposing several ways this could be triggered that had nothing to do with what ever is being changed in the exposed form handler I suspect might not being addressed based on a skim of the current patch.

dewalt’s picture

Status: Needs work » Needs review

@larowlan, I've made research of the issue and tried to provide explanation in #131. If anyone have some exact questions - you are welcome.

@neclimdul Do you propose just to add the Unit test from #130?

smustgrave’s picture

Status: Needs review » Needs work

Think the confusion is that in 129-130 the size was about 8KB

Then your post went to around 2KB with an explanation

But then in 139 it jumped up to 13KB

Was anything lost in that jump back down to 5KB, if tests were lost could we add back?

May help to hide all patches but the right one (making sure it matches the issue summary, didn't check). Also quickest solution is turn to an MR

xurizaemon’s picture

Assigned: Unassigned » xurizaemon
Issue tags: +DrupalSouth 2024

Taking a look at this - aim to restore the test improvements from #130. Will move this to an MR per smustgrave suggestion.

xurizaemon’s picture

Some MRs from DrupalSouth 2024:

  • !7154 is approach and tests from #130 (which had subsystem maintainer signoff in #113 and #120)
  • !7145 was tests from #130 + solution approach from #131, I am closing this as tests didn't pass

xurizaemon’s picture

Removing old patches from display, MR here is approach + tests from #130 updated.

Interdiff is not cooperating with me trying to get an interdiff from 130 to the MR, so I'll summarise as best I can from visual review:

  • Change from 130 to core/phpstan-baseline.neon moves to core/.phpstan-baseline.php
  • In FilterDateTest.php we pass form options as strings not integers now ($this->getSession()->getPage()->findField($filter_identifier)->selectOption('1'); not ...->selectOption(1);
  • declare(strict_types=1); in NumericFilterTest.php
xurizaemon’s picture

Status: Needs work » Needs review

Missed status update, back to NR

smustgrave’s picture

Status: Needs review » Needs work

Hiding patches for clarity.

Left a comment on the MR that may need to be clarified. If I'm correct that it's the wrong key then surprised nothing broke.

xurizaemon’s picture

Assigned: xurizaemon » Unassigned
Issue summary: View changes
StatusFileSize
new20.34 KB

Workaround added to issue description - if step 6 from the issue description is omitted, the bug does not appear.

Reproducible on 11.x, updated repro details in the issue description to use "Authored on" as that makes it easier to verify results on an empty site (create two test nodes, set "Authored on" date back for one node). View config I tested with here.

xurizaemon’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Test coverage can be seen https://git.drupalcode.org/issue/drupal-2825860/-/jobs/1173292

Following the issue summary believe I am able to see the issue and the MR does address it.

Also appears all feedback for this bug has been addressed so believe this one is good.

alexpott’s picture

Assigning issue credit. Not crediting screenshot confirming bug, or works for me, or doesn't work for me. Trying to credit people who moved the fix and issue forward. If I make a mistake I'm sorry! Thanks.

alexpott changed the visibility of the branch 2825860-notice-undefined-index to hidden.

alexpott’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed ba08bc0dcb to 11.x and b5f62fa4ae to 10.3.x and f78530b4a7 to 10.2.x. Thanks!

  • alexpott committed f78530b4 on 10.2.x
    Issue #2825860 by xurizaemon, Matroskeen, dewalt, neclimdul, joseph....

  • alexpott committed b5f62fa4 on 10.3.x
    Issue #2825860 by xurizaemon, Matroskeen, dewalt, neclimdul, joseph....

  • alexpott committed 64de6a69 on 11.x
    Issue #2825860 by xurizaemon, Matroskeen, dewalt, neclimdul, joseph....

Status: Fixed » Closed (fixed)

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

smitghelani’s picture

StatusFileSize
new1.9 KB

Re-roll of patch #48 for branch 10.3.x.

irafah’s picture

I had the same issues, applied the patch from #175 and it worked correctly. It seems it is still needed even after the previous merge at #170

rossb89’s picture

Agreed. The work here that was committed in 10.2.x, 10.3.x, 11.x is absolutely needed, but i'm still having issues with the actual value.

Inside here:

if (!empty($info[$this->operator]['values'])) {
  switch ($info[$this->operator]['values']) {
    case 1:
      if ($value['value'] === '') {
        return FALSE;
      }
      break;

    case 2:
      if ($value['min'] === '' && $value['max'] === '') {
        return FALSE;
      }
      break;
  }
}

for grouped (checkbox?) input, $value is this:

array (
  1 => '1',
)

which causes the error still as there is no 'value' key to check against for this grouped exposed input value.

Patch 175 which is a re-roll of 48 actually checks to inspect $value to make sure that the expected keys are there which seems to be what's needed in some circumstances?

There is another issue here in relation to this though... where ViewsExposedForm::submitForm() https://git.drupalcode.org/project/drupal/-/blob/10.3.x/core/modules/vie...

seems to declare an $exclude variable at the top of the function, which is added to if acceptExposedInput() returns false but then immediately beneath this outside of the loop, it's declared again (with the same initial keys) which overrides any entries that were added by this loop!

So you can get into a weird situation where the handler for the exposed input returns false, but then beneath it can still be processed as it's no longer inside of $exclude... which in my circumstances is actually useful as I want the exposed filter value to be valid... but technically it shouldn't be doing this!?

Maybe someone with some more knowledge around this could provide some insights about the data structure of grouped $value's and how this is expected to work without the additions in patch 175...

Update: Turns out in this instance the indexed field type of this field in SOLR was text, but in reality even though the field was stored as a yes / no value, the intention for purposes of searching is a boolean.
After modifying the field type to boolean in the search api configuration and modifying the indexed value before being indexed to be a boolean true / false instead of string yes / no, FilterPluginBase is used instead of NumericFilter and doesn't have this problem with the grouped output.

Just writing my ramblings here in case it helps anyone in the future.

rsych’s picture

StatusFileSize
new1.86 KB

Re-roll of patch #175 for branch 11.2.4.

oily made their first commit to this issue’s fork.

oily’s picture

Tried to fix merge conflict in 11.x branch. It looks like the 3 changed files need to be reverted? e.g. The Group attribute needs to be used not the Group annotation. I just realised this issue is closed.

acbramley’s picture

@oily the fix has been committed to 11.x

fabianfiorotto’s picture

StatusFileSize
new2.02 KB

Re-roll of patch #178 for branch 11.3, and also added a line for exposed operator.

adel-by’s picture

StatusFileSize
new2.26 KB

Re-roll for 11.3.9

acbramley’s picture

The fix already exists in 11.3, it was committed to 11.x 2 years ago.