Issue Bug Resolved

#111246SlidingWindowPagination creates wrong pages numbers if using default maximumNumberOfLinks

S P 10/26/26, 08:38 updated 11/11/26, 20:00

Description

If you use the SlidingWindowPagination just with a Paginator and the implicit default maximumNumberOfLinks = 0 setting, it can generate a pointless range:

{pagination.allPageNumbers -> f:debug()}

yields for example (page numbers “1,0”, both decreasing and 0 make no sense)

    array(2 items)
       0 => 1 (integer)
       1 => 0 (integer)

In the end this is due to $delta being 0 by default:

    $delta = floor($maximumNumberOfLinks / 2);
    $this->displayRangeEnd = (int)($currentPage + $delta - ($maximumNumberOfLinks % 2 === 0 ? 1 : 0));

Also the initialisation of $maximumNumberOfLinks is rather odd. Shortened from the class:

    private int $maximumNumberOfLinks = 0;

    public function __construct(PaginatorInterface $paginator, int $maximumNumberOfLinks = 0)
    {
        if ($maximumNumberOfLinks > 0) {
            $this->maximumNumberOfLinks = $maximumNumberOfLinks;
        }
    }

Everything defaulting to 0 and then comparison to 0.

I think the member var and the ctor arg should both default to something meaningful like 10. The conditional set if > 0 makes total sense, but only has a meaning if the default is also >0 in the first place.

Another viable option is to make the ctor arg $maximumNumberOfLinks mandatory. Optional with a meaningless/wrong default value makes no sense, however.

Reviews 2

History 48

  1. Wouter Wolters commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-11-11T20:00:15+00:00" > 11/11/26, 20:00 </span>

    Applied in changeset commit:28a575799cd33a232750a9bb1b7311ac60b98d72.