I added a filter plugin which uses hook_preprocess_views_view instead of hook_views_pre_view. Using a filter plugin takes care of all the prepopulation of values and form widgets, so that code ends up much simpler.
Using hook_preprocess_views_view instead of hook_views_pre_view also means the filter plugin has been fully initialized, so I was able to call a function on the plugin class instead of handling everything in the hook.
I'd love for some feedback on this, I'm wondering if this is un-usable for some use cases because of something I might have missed and lost from the field plugin.
I originally tried to add some features with the field plugin, but I found it to be very difficult. I think going forward it might be very challenging and error prone to leave as a field plugin.
- #3147181: Default fields Having default values is difficult because of the way the exposed filters are populated and when. Setting them at the time of pre_view will get overridden later by setUserInput.
- #3042469: Initial view should properly reflect fields that are on or off Actually setting the default values for the form element is also hard because it will get overridden by setUserInput
- #3096312: Views Fields On/Off: Expose pseudo filter field in the list of Filters so it can be sorted for display The exposed filter created by the field plugin is technically not a filter plugin, so its weight can't be set in comparison to the other filters. It always shows up as first, and that will be very challenging to control.
- Using BEF to control the multiple select to be a dropdown of checkboxes, this was pretty crucial for our instance because there are a lot of fields and it's very hard to control with the regular multiple select widget.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 13751742.patch | 3.13 KB | asherry |
Comments
Comment #2
asherry commentedComment #3
asherry commentedComment #4
asherry commentedComment #5
asherry commentedComment #6
asherry commentedComment #7
asherry commentedI'm sorry, the last patch had a missing bracket and was returning a php error.
Comment #8
andileco commentedThanks, @asherry - definitely going to take a close look at this.
Comment #10
andileco commentedAwesome patch! I adjusted
getValueOptions()to remove the relationship from the field label (this was a patch for the field that works well here too).Comment #11
andileco commentedAnyone still visiting this issue, please take a look at the related issue, "Enable earlier processing of Views Fields On/Off filter" - there's a new "bypass hook_views_pre_view" field in the filter settings that enabled using preprocess_views_view. If you want to use preprocess_views_view, check the box.