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.

CommentFileSizeAuthor
#7 13751742.patch3.13 KBasherry
#3 13751742.patch3.14 KBasherry

Comments

asherry created an issue. See original summary.

asherry’s picture

Status: Active » Needs review
StatusFileSize
new3.14 KB
asherry’s picture

Issue summary: View changes
asherry’s picture

asherry’s picture

Issue summary: View changes
asherry’s picture

StatusFileSize
new3.13 KB

I'm sorry, the last patch had a missing bracket and was returning a php error.

andileco’s picture

Thanks, @asherry - definitely going to take a close look at this.

  • andileco committed ddc2a36 on 8.x-1.x authored by asherry
    Issue #3159852 by asherry, andileco: Create filter plugin for on/off...
andileco’s picture

Status: Needs review » Fixed

Awesome patch! I adjusted getValueOptions() to remove the relationship from the field label (this was a patch for the field that works well here too).

andileco’s picture

Anyone 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.

Status: Fixed » Closed (fixed)

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