Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Steps to reproduce:
- Add a numeric field to user
- Edit the admin/people view
- Add a filter for the age field
- Expose it and group it (you'll have to click apply and re-edit the filter due to #2356259: Can not expose a filter immediately after adding a filter)
- Set up some groups (because of double escaping and a bug you'll have to apply #2356443: Grouped numeric filters can not have a value set and #2356297: Double escaping in views ui grouped filters)
- Apply the filter
- Save the view
This breaks because the value schema is incorrectly defined.
Proposed resolution
We fix numeric filter and filter group items config schema to match the configuration. This is not simple because the numeric filter value can either be a mapping or value at the moment. This type of polymorphism is not supported by config. Also the views_filter
schema data type is incorrect because views.filter.group_items.[plugin_id]
is never actually defined.
Remaining tasks
Commit it
User interface changes
None
API changes
Views config structure for views with numeric filter
Comment | File | Size | Author |
---|---|---|---|
#44 | 2357145.44.patch | 8.6 KB | YesCT |
#44 | interdiff.2357145.42.44.txt | 567 bytes | YesCT |
#42 | 2357145.42.patch | 8.63 KB | olli |
Comments
Comment #1
dawehnerAdapting the title a bit. Thanks for filling all those issues!
Comment #2
alexpottHere's a first cut at a patch
Comment #3
alexpottComment #4
alexpottIgnore #2
Comment #6
vijaycs85makes sense.
Why are we removing filter? we can add views.filter_value.date, if it missing.
Comment #8
alexpott@vijaycs85 #2 - because the only thing that is different about the numeric filter is the value so falling back to views.filter.* is fine
Comment #9
dawehnerThis adds a regression, previously the URL for exposed filters looked like ?operator=value, now it contains the value as well. (yeah I manually tested this)
Comment #10
alexpottRe #9 yeah but we already have this in Drupal\views\Plugin\views\filter\Numeric::valueForm() when the form is not exposed or the operator not locked. This makes the configuration consistent.
Comment #11
alexpottAdded a test that exposes the fatal error - actually because of that this is a critical. The interdiff is the test only patch :)
Comment #12
alexpottIt'd be great to add far more test coverage of the numeric filter ui
Comment #14
olli CreditAttribution: olli commentedI agree with #9, I don't see why we need to change the exposed form. How can I reproduce the problem?
Comment #15
alexpottre #14 to reproduce the problem the issue is solve follow the steps in the issue summary.
re #9 we can not have polymorphic variable types in config the numeric filter value can not be both a number or a mapping to value, min and max. The following two variants can not be described by the same schema:
Comment #16
olli CreditAttribution: olli commentedI applied #11 and two patches from step 5, reverted changes in #9, followed steps 1-7 and didn't see a problem. Maybe I did something wrong but the way I see #9, that affects only (single) exposed filters when they are rendered at admin/people.
Comment #17
alexpottre #16 you're not seeing a problem because there is no test to ensure that a view complies with its schema data type. And the value key exists - you're saving a number and the schema says it should be an array but that does not cause an error at the moment. What does cause an error is if you try to save value.value and the schema does not exist for that.
Comment #18
olli CreditAttribution: olli commentedThis is what I was trying to reproduce by checking the single export page for the view I created with the setup #16. What kind of filter I need to add so that it would save a number rather than an array with value, min and max, or is it just impossible to reproduce this with the UI?
Comment #19
alexpottThis is the situation in HEAD that would generate configuration where value is a scaler and not an array.
Comment #20
vijaycs85not sure why we need to have multiple of 'value'. but worth adding a comment why.
otherwise, +1 to RTBC.
Comment #21
olli CreditAttribution: olli commentedMe too. Maybe bot can help us.
Comment #22
alexpottI finally get what's happening here - the numeric form can be completely different if it is exposed on an actual view instead of the views ui. So when saving a filter it will always have the correct config structure. The key thing I missed was that:
Will never occur in the views ui whilst configuring the filter.
Thanks @olli for pushing until I understood this :)
Improved the test to actually test filtering too.
Comment #23
YesCT CreditAttribution: YesCT commentedthis is just the patch from #21 with the interdiff from 22 applied on it.
(patch in #22 looks like it has unrelated changes in it.)
Comment #24
YesCT CreditAttribution: YesCT commentedjust a couple nits (copy and paste error, and looked to see how white space was used usually in schema.)
to see why this test works, check out ViewTestData.php which has ages.
I'm not sure if I made the tests only patch correctly.
Comment #26
alexpottTest only patch failed as expected
Comment #27
olli CreditAttribution: olli commentedThank you for fixing this. I checked out ViewTestData.php and the test looks good to me. Two questions:
Should we add something similar for date here or in another issue?
Looks like this is not used in the test? Maybe add one min-max value?
Comment #28
olli CreditAttribution: olli commentedAdded a min-max value and a check for default values.
I'll open another issue for the date filter.
Comment #29
olli CreditAttribution: olli commentedHere's the issue to improve grouped date filter #2369119: Fatal error when trying to save a View with grouped filters using other than string values.
Comment #30
vijaycs85Looks good.
intersting that DefaultCofigSchema.test didn't fail :(
Comment #32
vijaycs85Comment #33
olli CreditAttribution: olli commentedComment #34
olli CreditAttribution: olli commentedRe #30 that might be related to #2331793: Changing pager settings for this display only also changes pager settings for other display. The pager_options exists in schema, but not sure it should.
Comment #35
olli CreditAttribution: olli commentedSorry, ignore #34. It's not related to DefaultConfigTest. The changed file is only tested by the test added here because the file is in sub-dir /test_views, not /config/install?
Comment #36
dawehnerAre we really sure that its a sane idea to allow false for a map?
Comment #37
olli CreditAttribution: olli commented#36: pager_options belongs to pager plugin now, similar to style_options?
Comment #38
dawehner---
Comment #39
dawehnerGot it, what you meant, so yes, the pager options are now stored below pager.options, so we can remove that entry completly.
Sorry for that previous answer!
Comment #40
dawehnerYou could also do that directly on the commeit.
Comment #42
olli CreditAttribution: olli commentedreroll
Comment #43
dawehner... you could have just just the pager_options bit
Comment #44
YesCT CreditAttribution: YesCT commentedIs this what you meant?
Comment #45
dawehnerYeah absolute!
Comment #46
dawehnerYeah absolute!
Comment #47
Dries CreditAttribution: Dries commentedIn my mind we wouldn't hold back the Drupal 8 release for this bug. I don't think it is a critical so I'm downgrading it to major, as per our issue priority guidelines for major bugs: "Issues that have significant repercussions but do not render the whole system unusable (or have a known workaround) are marked major". I committed the patch to 8.0.x. Thanks!