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.
The current module does not properly work with date fields because granularity us a very common use case:
- Filter handler is overriden and granularity (wich is important in this scenario) cannot be set, the generic selective handler does not allow for particular field filter configuration options.
- Filter distinct values are generated from field values, but granularity cannot be set on database retrieved values.
Comment | File | Size | Author |
---|---|---|---|
#4 | 2215585_views_selective_filters_dates_distinct_1.patch | 2.09 KB | jaime@gingerrobot.com |
#2 | 2215585_views_selective_filters_dates_distinct.patch | 2.02 KB | jaime@gingerrobot.com |
Comments
Comment #1
david_garcia CreditAttribution: david_garcia commentedComment #2
jaime@gingerrobot.com CreditAttribution: jaime@gingerrobot.com commentedHi,
I had to get a exposed filter working with only the years showing. This module exposes the entire time stamp as the id for the field. It also doesn't do a distinct on the dates. This is only part of the solution to making dates work. I also wrote a seperate views_query_alter to actually select the right rows.
Jaime.
Comment #3
david_garcia CreditAttribution: david_garcia commentedI am not very fond of the proposed solution.
I think the way to go is create a new implementation of
class views_handler_filter_selective extends views_handler_filter_in_operator
where we extend the date operator and customize it.
We would also probably need a superclass for both of them, to encapsulate functionality that is common to both handlers.
Comment #4
jaime@gingerrobot.com CreditAttribution: jaime@gingerrobot.com commentedQuick update to the patch to be more generic and select dates.
Just saw your comment now david! Thanks so much. I'll update here if I do any more changes.
Comment #5
joncjordan CreditAttribution: joncjordan commentedAny patches for the latest release 7.x-1.3?
Comment #6
david_garcia CreditAttribution: david_garcia commentedAlthough the patch works....
What you are doing is retrieving ALL database records, and then filter programatically.
This will not scale. This is the kind of thing that makes Drupal slow. That's what in spanish we call a "Pan para hoy y hambre para mañana" patch.
Distinct values should be retrieved by the database engine :)
Take a look at the dev version and the commit least, at least 2 new patches have gone into the module since the 1.3 release.
Comment #7
joncjordan CreditAttribution: joncjordan commentedWas this particular patch committed? If so, do I need to do anything else to get this module working for post dates? Like jaimekristene I need an exposed filter with only the years. When I use views selective filters on the post date, it is returning duplicates.
Any thoughts? How can we strip the timestamp and just use the year or month?
Comment #8
joncjordan CreditAttribution: joncjordan commentedSo as I research this further, it appears that views selective filters only works when it is returning a timestamp in the url. If it returns something like &created_selective=April+2015, it won't have any results. I'm at a loss :(
Comment #9
NitebreedWhat you also need to do is override the op_simple() function within views_handler_filter_selective to something like this:
This is an ugly workaround, but hey, it works.
What needs to be done for this issue imo is the following:
- Create a new filter for dates only
- Use the structure that already exists for the date filter within views
- Rewrite the options accordingly
Comment #10
froboyI came upon this and had a few tweaks, but got it mostly working:
As noted a few places above, the date filtering in the patch mostly works, with a few changes:
- you'll need to change
field_content_date
to the id of your field (in my case below it wasfield_date
)- The "$year..." line needs to have strtotime included:
$year = date("Y",strtotime($key));
That should get the filter selective-ness working, from there you'll still need a views query alter. Here's what I had to do:
Hope that helps someone in the future.