Skip to content

Commit 4e56852

Browse files
authored
Merge pull request #261 from extcode/259-replace-simplepagination-with-slidingwindowpagination-backport
[TASK] Replace SimplePagination with SlidingWindowPagination
2 parents b63d86f + 718d7e2 commit 4e56852

8 files changed

Lines changed: 78 additions & 11 deletions

File tree

Classes/Controller/ProductController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Extcode\CartProducts\Domain\Repository\CategoryRepository;
1818
use Extcode\CartProducts\Domain\Repository\Product\ProductRepository;
1919
use Psr\Http\Message\ResponseInterface;
20-
use TYPO3\CMS\Core\Pagination\SimplePagination;
20+
use TYPO3\CMS\Core\Pagination\SlidingWindowPagination;
2121
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
2222
use TYPO3\CMS\Core\Utility\GeneralUtility;
2323
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
@@ -154,19 +154,20 @@ public function listAction(int $currentPage = 1): ResponseInterface
154154
$demand = $this->createDemandObjectFromSettings($this->settings);
155155
$demand->setActionAndClass(__METHOD__, self::class);
156156

157-
$itemsPerPage = $this->settings['itemsPerPage'] ?? 20;
157+
$itemsPerPage = (int)($this->settings['itemsPerPage'] ?? 20);
158+
$maximumNumberOfLinks = (int)($this->settings['maximumNumberOfLinks'] ?? 0);
158159

159160
$products = $this->productRepository->findDemanded($demand);
160-
$arrayPaginator = new QueryResultPaginator(
161+
$paginator = new QueryResultPaginator(
161162
$products,
162163
$currentPage,
163164
$itemsPerPage
164165
);
165-
$pagination = new SimplePagination($arrayPaginator);
166+
$pagination = new SlidingWindowPagination($paginator, $maximumNumberOfLinks);
166167
$this->view->assignMultiple(
167168
[
168169
'products' => $products,
169-
'paginator' => $arrayPaginator,
170+
'paginator' => $paginator,
170171
'pagination' => $pagination,
171172
'pages' => range(1, $pagination->getLastPageNumber()),
172173
]

Documentation/Administrator/Configuration/TypoScript/Index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ EXT:cart.
2525
format.currency < plugin.tx_cart.settings.format.currency
2626
2727
itemsPerPage = 9
28+
maximumNumberOfLinks = 0
2829
}
2930
}
3031
@@ -49,3 +50,10 @@ the individual parameter are described.
4950
:Default: The default value is 20 if there is no TypoScript configuration.
5051

5152
Defines how many records should be displayed per page in the list action.
53+
54+
.. confval:: maximumNumberOfLinks
55+
56+
:Type: int
57+
:Default: The default value is 0 if there is no TypoScript configuration.
58+
59+
Defines how many links the paginator should show. The default value 0 means that the page links are not limited.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. include:: ../../Includes.rst.txt
2+
3+
=====================================================================
4+
Feature: #259 - Replace SimplePagination with SlidingWindowPagination
5+
=====================================================================
6+
7+
See `Issue 259 <https://github.com/extcode/cart_products/issues/259>`__
8+
9+
Description
10+
===========
11+
12+
If you have a long list of products, you would like to display them in a pagination
13+
with a defined number of products per page. This is already possible with the
14+
TypoScript configuration `itemsPerPage`. With a large number of products, the
15+
display of all page links may not work well, especially when it comes to the
16+
display on mobile devices.
17+
The TYPO3 core offers the SlidingWindowPagination since TYPO3 v12.
18+
This is compatible with the previously used SimplePagination if you pass the
19+
value 0 for the number of links.
20+
21+
Integration
22+
===========
23+
24+
Set the new TypoScript configuration variable `plugin.tx_cartproducts.maximumNumberOfLinks` to a value greater than 0.
25+
If you use an own template file for `Resources/Private/Partials/Utility/Paginator.html` you have to adapt the changes
26+
to your file.
27+
28+
.. index:: Frontend
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. include:: ../../Includes.rst.txt
2+
3+
6.1 Changes
4+
===========
5+
6+
**Table of contents**
7+
8+
.. contents::
9+
:local:
10+
:depth: 1
11+
12+
Features
13+
^^^^^^^^
14+
15+
.. toctree::
16+
:maxdepth: 1
17+
:titlesonly:
18+
:glob:
19+
20+
Feature-*

Documentation/Changelog/Index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ChangeLog
1010
:maxdepth: 5
1111
:titlesonly:
1212

13+
6.1/Index
1314
6.0/Index
1415
5.0/Index
1516
4.0/Index

Documentation/guides.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
interlink-shortcode="extcode/cart_products"
1212
/>
1313
<project title="Cart Products"
14-
release="6.0.1"
15-
version="6.0"
16-
copyright="2018 - 2024"
14+
release="6.1.0"
15+
version="6.1"
16+
copyright="2018 - 2025"
1717
/>
1818
<inventory id="t3tsref" url="https://docs.typo3.org/typo3cms/TyposcriptReference/"/>
1919
</guides>

Resources/Private/Partials/Utility/Paginator.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@
1717
<li class="disabled"><a href="#" class="btn btn-link">&lsaquo;</a></li>
1818
</f:else>
1919
</f:if>
20-
<f:for each="{pages}" as="page">
20+
21+
<f:if condition="{pagination.hasLessPages}">
22+
<li></li>
23+
</f:if>
24+
25+
<f:for each="{pagination.allPageNumbers}" as="page">
2126
<li class="{f:if(condition: '{page} == {paginator.currentPageNumber}', then:'active', else:'waves-effect')}">
2227
<a href="{f:uri.action(action:actionName, arguments:{currentPage: page})}" class="btn btn-link">{page}</a>
2328
</li>
2429
</f:for>
2530

31+
<f:if condition="{pagination.hasMorePages}">
32+
<li></li>
33+
</f:if>
34+
2635
<f:if condition="{pagination.nextPageNumber} && {pagination.nextPageNumber} <= {pagination.lastPageNumber}">
2736
<f:then>
2837
<li class="waves-effect">
@@ -39,4 +48,4 @@
3948
</f:if>
4049
</ul>
4150
</f:if>
42-
</html>
51+
</html>

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'title' => 'Cart - Products',
55
'description' => 'Shopping Cart(s) for TYPO3 - Products',
66
'category' => 'plugin',
7-
'version' => '6.0.1',
7+
'version' => '6.1.0',
88
'state' => 'stable',
99
'author' => 'Daniel Gohlke',
1010
'author_email' => 'ext@extco.de',

0 commit comments

Comments
 (0)