Short version:

I'm trying to save one filter field in the submit functiion of another filter field. I've form altered views_ui_config_item_form to add a custom dropdown and custom submit function to save the value of that dropdown (in another filter field). What's the best way to save a filter field inside the submit function of another filter field?

Long version:

I'm trying to create a module that creates composite filters (groups). Sandbox: http://drupal.org/sandbox/rudiedirkx/1785634

I'm doing that by altering all views_ui_config_item_form for "filter" types to add a "Composite Views Filter Group" dropdown. Obviously I can't save the group into that field, because I can't alter its option_definition. And I don't want to. I want to extract the selected Group and save it into my custom Filter field.

So what I'm doing is add a submit handler (at the end) in views_ui_config_item_form to get the selected Group and save it into my own Filter field: fetch custom filter, save options into filter, save filter into view, save view with views_ui_cache_set.

I'm guessing Views isn't built for my hack: save one filter field handler in the submit functiion of another filter field handler. It does work, but the result is sometimes somewhat unexpected:

  1. I create a new group in my custom filter field
  2. I add a new filter and select the new group
  3. I preview the display: all composite filters are ignored/removed (that's default)
  4. In the exposed filter I select an old (previously existing) group: the correct filters work
  5. In the exposed filter I select the new group: it's not applied. All composite filters are ignored. It's like the entire new filter doesn't in the current view (but it does! I can see so in hook_pre_view)
  6. I save the View exactly like this
  7. I preview it => all works, incl new and old composite filters

I think it's because I hack my way around saving my custom filter field handler and mess up something in/with views_ui_cache_set. I think so because the View works perfectly after saving (not ui_cache'd), but fails strangely when previewing changes (after ui_cache'd).

Long story. Sorry. Ideas, tips?

Steps to reproduce (if for some reason you decide to clone my sandbox module and try it out):

  1. Create new view (Content).
  2. Create filter: "Global: Composite Filter" with >= 1 groups (and expose it!).
  3. Add filters (Node or Content etc) and assign them to a "Composite Views Filter Group".
  4. Save.
  5. Preview: the exposed filter should have >= 2 options: "- All -" and your groups. All should work as expected. So far so good.
  6. Edit the Composite filter: add a new group
  7. Add a filter and assign it to the new group
  8. Don't save!
  9. Preview: the exposed filter works only for the old groups. The new group and new filter are ignored. The SQL conditions aren't added.

Comments

MustangGB’s picture

Status: Active » Closed (outdated)