Problem/Motivation
We need to use entity_pager with a paginated view.
It might be an edge use case, but we basically need to have prev/next links only for a given page of the view (links should stop when reaching the end of the current page).
To do this, we call EntityPagerFactory::get() manually on our paginated view.
Everything works correctly, except the count which does not handle the offset correctly.
Steps to reproduce
Create a view with 100 results, which displays 50 results per page.
Build a block with this code:
Views::getView('foo');
$view->setCurrentPage(1);
$links = $this->pagerFactory->get($view, ['relationship' => []])->getLinks();
Display it on the third node of the page.
The count is "3 of 100" instead of "53 of 100".
Proposed resolution
EntityPager::getCount() should add the offset to the count.
Issue fork entity_pager-3277420
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
prudloff commentedComment #4
wongjn commentedComment #5
joachim commentedCouldn't this be done by adding the 'Display a specified number of items' pager to your view, and controlling which items show with that?
Comment #6
prudloff commentedWe do have a pager on this view and we want to keep it.
It's a bit hard to describe our use case because it involves some custom code. We basically have a standard pager + an entity pager that allows scrolling through the entities in the current page.
I'll try to provide a simpler way to reproduce.
Comment #7
prudloff commentedHere is how to reproduce without custom code (with 1.0.0):
Browse to the node that is the fourth result of the view (so the last node of the second page.) with
?page=1in the URL (so that the node is in the current page results).I know combining a classic pager with the entity pager is a very specific use case. (We basically have a paginated list of nodes at the bottom of the page + the current node and an entity pager at the top, so users can go the previous/next node but only within the current page).
Comment #8
joachim commented> Let's say the view has 4 results and display 2 results per page
Right, that's the problem there. Don't set 'display results per page' to a number other than 1 -- it does not make sense in the context of the entity pager!
> The count says "2 of 4" but it should say "4 of 4", because the node we are on is the last result of the view.
I don't understand this. In your use case, shouldn't I see only up to 2 on either of the view's 2 pages?
Comment #9
prudloff commentedIt does make sense in our specific use case: having an entity pager that covers the current page of a larger view with multiple pages.
But I understand if this is too specific for the module to support. I'll see if we can do this entirely in custom code.
No, we do want to see where we are relative to the entire list of results. But again I get that it is a very specific use case.