When a view with an exposed filter with a 'locked' operator is exported, the exported version of the view will show the operator as 'unlocked'.
During export, each options value is checked against the default value for that option; if it's a default value, the option does not get exported. The 'operator' setting for exposed filter options, though, is never the same as the default value, because it gets set by the expose_options() method as $this->options['id'] . '_op'. That would be fine, except that there is a snippet of code that sets use_operator to TRUE when 'use_operator' is not set but 'operator' is set--and with exported views, this is exactly the case (because of the default values behavior).
The snippet of code in question is in the views_handler_filter class's init method:
// Compatibility: Set use_operator to true if the old way of using
// the operator is set and use_operator is NULL (was never set).
if (!empty($options['exposed']) && !empty($options['expose']['operator']) && !isset($options['expose']['use_operator'])) {
$this->options['expose']['use_operator'] = TRUE;
}
There are probably a couple of ways to address this; the attached patch implements views_handler_filter::expose_submit() and unsets the 'operator' value when 'use_operator' is falsey so that the 'operator' value doesn't get saved.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 933716-6.x.patch | 917 bytes | bojanz |
| #18 | 933716-7.x.patch | 948 bytes | bojanz |
| #4 | 933716-4-views-export_exposed_filters.patch | 869 bytes | becw |
| #2 | 933716-3-views-export_exposed_filters-6.x-3.x.patch | 1.27 KB | becw |
| views-export_exposed_filters.patch | 1.05 KB | becw |
Comments
Comment #1
dawehnerThis should be a bug in 6.x, too.
Comment #2
becw commentedI confirmed that this is also an issue with 6.x-3.x. The same fix works--and the original patch applies with a little fuzz. If it's more convenient, here's a fresh patch against DRUPAL-6--3.
(edit: oops, used the wrong comment # in the patch file name, and I can't fix it now.)
Comment #3
dagmarI can confirm this bug, and the patch fix a part of the issue.
However, I found a case that is not covered.
To replicate.
Create a view with an exposed filter without operators.
Apply the patch.
Export the view.
Import the view with other name.
As you can see, the operator is locked again. So this patch work only if user 'save' the view after apply the patch. I think this should be fixed in the export and not in the filter submission.
Comment #4
becw commentedOne alternative way to solve this is to force Views to export the 'use_operator' setting for filters; here's a new patch that fixes the issue that way, by changing the default value to FALSE instead of 0 (functionally equivalent, but since forms will return 0 for false, the filter setting will be 'different' according to the === operator). I think this is less sensible than the first patch.
Either way, views exported before this patch will need to be either edited (delete the 'operator' setting for filters without exposed operators) or re-exported.
Comment #5
Remon commentedsubscribe
Comment #6
Hwangar commentedsubscribing too...
Comment #7
blakehall commentedSubscribing.
(And the patch in #2 seems to be working for me)
Comment #8
amitaibusorry for doing this, but subscribe
Comment #9
robertgarrigos commentedI had this problem with views-7.x. patch #2 didn't fix the problem, but it did it patch #4.
Will you commit this to views-7.x also? I've seen this issue (http://drupal.org/node/963010) for views-7.x tagged as duplicate of this one, so I don't know where to ask.
Comment #10
merlinofchaos commentedWhat if we just remove that compatibility code? It's 2 years old at this point, and dates back to pre 2.0 changes. I don't think it matters anymore.
Comment #11
robertgarrigos commentedI think it matters if you need to add a view to a feature. In this case you get this problem in D7
Comment #12
merlinofchaos commentedNo no, I don't mean the patch; I mean the compatibility code that causes the setting to be changed.
i.e, what if we remove this:
Comment #13
merlinofchaos commentedCertainly in Views 3, that code is not necessary at all.
Comment #14
danielnolde commentedOkay, this flaw in views' exportables support caused many people unnecessary trouble over months (years?) and makes ugly form_alter-workarounds necessary (or you could fix it manually in the features file but would always get an "overridden" status...).
So what's the status?
Does either the patch from Rebecca in dev or the troublesome compatibility code out of dev, as proposed by Earl??
Comment #15
entrigan commentedI commented out the lines in views_handler_filter.inc specified in #12, and this appears to have resolved the issue.
Comment #16
kehan commentedI have a features based set of modules which use views & exposed filters extensively. Above fix works for me too 7.x-1.x-beta3
Comment #17
daniel_j commentedSubscribing
Comment #18
bojanz commentedOkay, let's do this (per #10)
Comment #19
damien tournoud commentedJust as the doctor ordered :)
Comment #20
klausiConfirmed, patch solves the problem.
Comment #21
jsenich commentedThe patch works for me.
Comment #22
betz commentedgood
Comment #23
scor commented#18 worked for me in D7. RTBC++
Comment #24
merlinofchaos commentedYes, let's kill this for all 6.x-3.x branches. Any views relying on this code are > 3 years old.
Comment #25
dawehnerOh there are more then one 6.x-3.x branch ;)
Commited to both 3.x branches.
Comment #26
Bevan commentedConfirmed fix in latest 7.x-3.x-dev release.