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.

Command icon 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

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
wongjn’s picture

Status: Needs review » Needs work
joachim’s picture

Status: Needs work » Postponed (maintainer needs more info)

Couldn't this be done by adding the 'Display a specified number of items' pager to your view, and controlling which items show with that?

prudloff’s picture

We 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.

prudloff’s picture

Status: Postponed (maintainer needs more info) » Needs review

Here is how to reproduce without custom code (with 1.0.0):

  1. Create a block view with a pager and the "Entity Pager" format.
  2. Place the block on nodes.
  3. Let's say the view has 4 results and display 2 results per page.
    Browse to the node that is the fourth result of the view (so the last node of the second page.) with ?page=1 in the URL (so that the node is in the current page results).
  4. 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 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).

joachim’s picture

Status: Needs review » Needs work

> 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?

prudloff’s picture

Status: Needs work » Closed (won't fix)

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!

It 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.

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?

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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.