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.
I would like to have an option for the views date pager that skips links to pages with no results.
For example, in case of a pager by month, when viewing march, let the previous month link to januari if there is no content for februari.
I'll try to find some time to come up with a patch.
Comment | File | Size | Author |
---|---|---|---|
#31 | views_date_pager-1487700-26.patch | 1.13 KB | El Alemaño |
#25 | views_date_pager-1487700-25.patch | 19.05 KB | Valentine94 |
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedThere is no easy way to do this. Basically it would require doing a query of the next and previous period, as is done now, checking to see if there are any results, if not do another query one more period out. See if there are any results for that. If not, do another query one more period out. Etc Etc. And what if there is NO period that has any matches? It might go on endlessly trying to find a period that has values. And those subsequent queries cannot be done at the time of the first query, but have to be done later, perhaps in pre_render. Performance would be terrible.
This sounds simple but is not.
Comment #2
casey CreditAttribution: casey commentedYou only need 2 queries. Closest previous and closest next date.
Comment #3
Jorrit CreditAttribution: Jorrit commentedcasey is right. Query for the previous item, figure out in which period it is, display the pager. If no results, don't display the pager.
Comment #4
KarenS CreditAttribution: KarenS commentedThis is not the way Views works, there is only one query, the original one. It doesn't do multiple queries with dynamic logic about what to do depending on the result of the first query. If you think this is cleanly solvable you'll have to come up with a patch, because I don't think it is. And I don't plan to try to figure it out, so this is not going to happen without a patch. Leaving it 'active' implies it is going to get done.
Comment #5
Jorrit CreditAttribution: Jorrit commentedI understand your position KarenS. However, my client really needs this so I have made a patch. Using a clone of the views query I was able to make this work with relatively few lines of code. The option to skip pages has been made optional with the default being off. I would very much like to hear your opinion on the patch.
I have not checked the patch for conformity with all possible use cases of the Date Views module, especially the special case of paging by week. I am not proposing this patch to be committed yet, I just want to get your opinion on it.
Comment #6
Jorrit CreditAttribution: Jorrit commentedPatch update: fixed a bug where the next pager was shown when it shouldn't be. Also fixed a bug in the original code where there was no format preset for the hour granularity.
I also fixed some code style issues.
I am marking this issue as "needs review" to see what the test bot thinks of it.
Comment #8
Jorrit CreditAttribution: Jorrit commentedThe failing test is "MigrateException: No migration found with machine name DateExample in MigrationBase::getInstance()". I don't think it is related to my patch. If it is, please let me know.
Comment #9
Jorrit CreditAttribution: Jorrit commentedThe patch has been working great for about two months now, let's see if the QA bot agrees with the patch now.
Comment #10
Jorrit CreditAttribution: Jorrit commented#6: date-views-skip-empty-pages-1487700-6.patch queued for re-testing.
Comment #11
sanduhrs#6: date-views-skip-empty-pages-1487700-6.patch queued for re-testing.
Comment #12
shortspoken CreditAttribution: shortspoken commentedThanks for the patch. Its all working fine BUT I found a bug with the week pager. It does not let me navigate to the PREVIOUS week as it always links to the currently selected. Its probably an issue around line 76 in the date/date_views/theme/theme.inc
Before patching its:
...
and afterwards
...
Maybe someone can find the bug. I appreciate any help!
Cheers, Moritz
using Date 7.x-2.7
Comment #13
robotjox CreditAttribution: robotjox commentedthis patch is not working for me. I have tried applying it manually, but it is behaving erradically for me - on my "events list" it is showing the "previous" pager for Months without any events in them whereas it seems to work for future dates.
I have tried to modify it without any luck - any chance of an updated patch or some pointers?
It is essential functionality for my site - users don't want to browse Months without any events.
Comment #14
Jorrit CreditAttribution: Jorrit commentedI only use this patch to skip empty days. I think you should look at the query generated by views to see if anything must be improved for skipping months.
Comment #15
robotjox CreditAttribution: robotjox commentedthanks for replying so quickly!
In your patch description you write "For example, in case of a pager by month, when viewing march, let the previous month link to januari if there is no content for februari."
That is exactly what I need - is the patch not designed to do this?
I have messed around with the code for hours to no avail, I'll keep on trying but I'm having a hard time figuring out where/how the code queries for previous and next events.
Comment #16
Jorrit CreditAttribution: Jorrit commentedThat is not what I wrote, that was casey. I made the patch just for my situation, which is skipping days. Of course my hope was that it would work for any kind of interval, but apparently it doesn't. It is too long ago for me to quickly see what changes are needed. I could try to find it when I have time, but it will take a while.
Comment #17
robotjox CreditAttribution: robotjox commentedOh, I'm sorry, I was too fast :-)
Thanks anyway - actually the patch works perfectly for Months as long as there are dates in the calendar - problems arise when there are no dates - in those cases both pagers show (although they shouldn't) and they both link to the current Month (which they shouldn't).
So my guess is that there needs to be some fallback for queries that do not reurn results. I'll update this thread if I find a solution.
Comment #18
El Alemaño CreditAttribution: El Alemaño commentedHi,
With Date Module Update date-views-skip-empty-pages-1487700-6.patch was not working. Here is the small update of the Patch.
Thanks!
Comment #20
Valentine94Re-roll and some coding standards fix's.
Comment #21
podarokI'll appreciate if You'll manual review #20
Code looks good for me
Comment #22
Valentine94I've created a some test.
Please let me know if this test should be more advanced.
Thanks.
Comment #24
Valentine94Comment #25
Valentine94I've created a some test and merged it with a latest patch.
Please let me know if this test should be more advanced.
Thanks.
Comment #26
Valentine94Comment #28
podarok#25 commited. Thanks!!!
Comment #30
Jorrit CreditAttribution: Jorrit commentedI fear I may have made a mistake in my patch which ended up being committed.
date_views_plugin_pager.inc
now contains two references to$granularity
that should not be there. They should be$this->view->date_info->granularity
.Comment #31
El Alemaño CreditAttribution: El Alemaño commented