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.
If there is no item at all in the result a view with a configured mini pager shows "Page".
To reproduce just switch one of the provided views to use the mini pager.
Comment | File | Size | Author |
---|---|---|---|
#12 | vdc-2049723-12.patch | 2.77 KB | tim.plunkett |
#12 | interdiff.txt | 1.03 KB | tim.plunkett |
#9 | vdc-2049723-9.patch | 3.33 KB | dawehner |
#9 | interdiff.txt | 1.91 KB | dawehner |
#5 | vdc-2049723-5.patch | 2.45 KB | dawehner |
Comments
Comment #1
dawehnerThere we go.
Comment #2
jibranThis is simple change.
Comment #3
mondrakeWell, do we need a pager at all if there are no results?
In the main template_preprocess_pager() in pager.inc we have
Couldn't we do the same for theme_views_mini_pager()?
Comment #4
mondrakeIn any case, one may theoretically want to 'reuse' the theme outside of views, and here we are tightening up the theme with a view. The global variable
$pager_total_items[$element]
would already be providing that info without having to access the view object.Comment #5
dawehnerGood point.
Comment #6
mondrakeSorry @dawehner, I realize my comment in #4 is more confusing than helping.
In fact, we do not need to access $pager_item_total, nor to check if it set. updatePageInfo() in SqlBase will set all the pager globals
after running the count query, including $pager_total. $pager_total counts the number of pages, $pager_total_items counts the records. So, if we want to have no pager in case of zero records, or in case of only one page of results (which is the main 'pager' behavior) then justshould be sufficient.
This
would render the pager in case there is only one page of results, but only if there is more than one record returned, which would be weird... :)
EDIT: updatePageInfo() is executed also if count query is not used
Comment #7
dawehnerPlease have a look at the mini pager and see how it is done internally. We hack around the fact that we neither know the total pages, nor we know the total items.
Comment #8
mondrakeAh ok I see that, sorry for the noise. Still, just tested on simplytest.me
- created 11 nodes
- using view Frontpage
- set mini pager, 10 items per page
- view shows 10 nodes + pager 'Page 1 next>>'
- delete 3 nodes
- view shows 8 nodes + pager 'Page 1' with no links
- delete all nodes but one
- view shows 1 node but no pager
- delete last node
- view shows no pager
So, the point is: do we want to show 'Page 1' if we have only one page of results, regardless of how many items on that page?
if YES, then I think we can do
if NO (my preference as it will align to main pager) can we do anything like
?
Comment #9
dawehnerSorry for my harsh tone yesterday, but I did not really had time to answer properly.
I highly appreciate a good discussion here, especially the point you made with being reusable.
I think 'Page 1' should not appear if there is no more page (basically exactly what the test shows).
What about checking for the pager links. If there is none, (neither to go back, or to go forward) then don't show the current page.
This seems to cover all cases, what do you think?
Comment #10
mondrakeTested on simplytest.me, following steps in #8. Patch works as described in #9. Has tests. RTBC for me.
@dawehner no need to apologize, in fact I found this discussion valuable.
The reason I have been picky on this one is that I proposed to build a Pager 'component' to replace the current pager functionality, see #2044435: Convert pager.inc to a service, and use classes and methods in place of the current globals.
Now this has been postponed to D9 and there will be time to discuss :), but the 'hack' for the Mini pager is for me a sign that we need to consider, in whatever the future design, that we may have to page on a set of data for which we do not know the total number of elements. This is a shortcoming of the current pager. I will add a comment to that issue too.
For the records: about the hack itself, I understand that in order to avoid double querying the db (once for the count, once for the records), the count query is not executed and the limit of the records-returning query is increased by one to check if there is a 'next' page. This is just used to flag, via postExecute, the need to render the 'next >' link by entering a fictitious high value in total_items, and the recordset is then reduced by one to go back to required behaviour. Fine - but in this case of 0 or 1 page in the view, the total_items will be anyway lower than the page limit, so via upatePageInfo() $pager_total will be set to 0 (if no records), or 1 (if there are records). So testing
$pager_total[$element] <= 1
should provide the same result...Comment #11
alexpottLooks like this change is no longer needed.
Comment #12
tim.plunkettVery true. Also removed the extra blank line that was being added, and added the correct return type.
Comment #14
mondrake#12: vdc-2049723-12.patch queued for re-testing.
Comment #15
mondrakeWill this have to be changed back to
return;
in the conversion to Twig? See #1912604: Convert theme_views_mini_pager to twig.Comment #16
mondrakeFeedback in #11 addressed, passes tests -> back to RTBC
Comment #17
alexpottCommitted 391755e and pushed to 8.x. Thanks!
Comment #18
dawehner#12: vdc-2049723-12.patch queued for re-testing.
Comment #20
mondrakeThis was committed already, see #17