From 82c5da12824a5fe22d83f93faa111ec5abc72c95 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Sat, 8 May 2021 19:49:33 +0200 Subject: [PATCH] Replace pagination widget in FE list Instead of using the widget.paginate, the indices are now paginated with the new pagination API. To limit the amount of pages, georgringer/numbered-pagination is suggested. Old templates with widget.paginate should still continue to work (in TYPO3 10 or until removed). Related: #542 --- Classes/Controller/CalendarController.php | 41 ++++++++++++- Configuration/TypoScript/setup.txt | 1 + Resources/Private/Partials/List.html | 20 +++---- Resources/Private/Partials/Pagination.html | 57 +++++++++++++++++++ .../Private/Templates/Calendar/Latest.html | 2 +- .../Private/Templates/Calendar/List.html | 2 +- .../Private/Templates/Calendar/Past.html | 2 +- .../Private/Templates/Calendar/Result.html | 2 +- .../Private/Templates/Calendar/Shortcut.html | 2 +- .../ViewHelpers/Widget/Paginate/Index.html | 1 + composer.json | 3 +- 11 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 Resources/Private/Partials/Pagination.html diff --git a/Classes/Controller/CalendarController.php b/Classes/Controller/CalendarController.php index 6126697b..93b41bfd 100644 --- a/Classes/Controller/CalendarController.php +++ b/Classes/Controller/CalendarController.php @@ -7,6 +7,7 @@ namespace HDNET\Calendarize\Controller; +use GeorgRinger\NumberedPagination\NumberedPagination; use HDNET\Calendarize\Domain\Model\Event; use HDNET\Calendarize\Domain\Model\Index; use HDNET\Calendarize\Register; @@ -16,13 +17,16 @@ use HDNET\Calendarize\Utility\TranslateUtility; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry; +use TYPO3\CMS\Core\Pagination\SimplePagination; use TYPO3\CMS\Core\Utility\ClassNamingUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; +use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator; use TYPO3\CMS\Extbase\Persistence\QueryInterface; +use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter; use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; @@ -141,6 +145,7 @@ public function latestAction( $this->slotExtendedAssignMultiple([ 'indices' => $search['indices'], + 'pagination' => $this->getPagination($search['indices']), 'searchMode' => $search['searchMode'], 'searchParameter' => [ 'startDate' => $startDate, @@ -190,6 +195,7 @@ public function resultAction( $this->slotExtendedAssignMultiple([ 'indices' => $search['indices'], + 'pagination' => $this->getPagination($search['indices']), 'searchMode' => $search['searchMode'], 'searchParameter' => [ 'startDate' => $startDate, @@ -241,6 +247,7 @@ public function listAction( $this->slotExtendedAssignMultiple([ 'indices' => $search['indices'], + 'pagination' => $this->getPagination($search['indices']), 'searchMode' => $search['searchMode'], 'searchParameter' => [ 'startDate' => $startDate, @@ -287,6 +294,7 @@ public function shortcutAction() } $this->view->assignMultiple([ + 'pagination' => $this->getPagination($fetchEvent), 'indices' => $fetchEvent, ]); } @@ -308,8 +316,11 @@ public function pastAction( $limit = (int)($this->settings['limit']); $sort = $this->settings['sorting']; $this->checkStaticTemplateIsIncluded(); + $indices = $this->indexRepository->findByPast($limit, $sort); + $this->slotExtendedAssignMultiple([ - 'indices' => $this->indexRepository->findByPast($limit, $sort), + 'indices' => $indices, + 'pagination' => $this->getPagination($indices), ], __CLASS__, __FUNCTION__); } @@ -699,6 +710,34 @@ protected function checkWrongDateOrder(\DateTime &$startDate = null, \DateTime & } } + /** + * Creates the pagination logic for the results. + * + * @param QueryResultInterface $queryResult + * + * @return array + */ + protected function getPagination(QueryResultInterface $queryResult): array + { + $paginateConfiguration = $this->settings['paginateConfiguration'] ?? []; + $itemsPerPage = (int)($paginateConfiguration['itemsPerPage'] ?? 10); + $maximumNumberOfLinks = (int)($paginateConfiguration['maximumNumberOfLinks'] ?? 10); + + $currentPage = $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1; + + $paginator = new QueryResultPaginator($queryResult, $currentPage, $itemsPerPage); + if (class_exists(NumberedPagination::class)) { + $pagination = new NumberedPagination($paginator, $maximumNumberOfLinks); + } else { + $pagination = new SimplePagination($paginator); + } + + return [ + 'paginator' => $paginator, + 'pagination' => $pagination, + ]; + } + /** * Get the allowed actions. * diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 13b5cf57..a4193f7a 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -46,6 +46,7 @@ plugin.tx_calendarize { 100 = {$plugin.tx_calendarize.view.layoutRootPath} } + // Deprecated: remove after Typo3 > 10 widget { TYPO3\CMS\Fluid\ViewHelpers\Widget\PaginateViewHelper { templateRootPath = EXT:calendarize/Resources/Private/Templates/ diff --git a/Resources/Private/Partials/List.html b/Resources/Private/Partials/List.html index fcfdb68f..49e432b4 100644 --- a/Resources/Private/Partials/List.html +++ b/Resources/Private/Partials/List.html @@ -11,18 +11,14 @@ - - - - - - - - - - You have to include the static typoscript to get the paginateConfiguration for list views - + + + + + + + + diff --git a/Resources/Private/Partials/Pagination.html b/Resources/Private/Partials/Pagination.html new file mode 100644 index 00000000..e9996099 --- /dev/null +++ b/Resources/Private/Partials/Pagination.html @@ -0,0 +1,57 @@ + diff --git a/Resources/Private/Templates/Calendar/Latest.html b/Resources/Private/Templates/Calendar/Latest.html index cc0393fa..deb4d605 100644 --- a/Resources/Private/Templates/Calendar/Latest.html +++ b/Resources/Private/Templates/Calendar/Latest.html @@ -2,6 +2,6 @@ - + diff --git a/Resources/Private/Templates/Calendar/List.html b/Resources/Private/Templates/Calendar/List.html index 06a39cd5..b3ab4b20 100644 --- a/Resources/Private/Templates/Calendar/List.html +++ b/Resources/Private/Templates/Calendar/List.html @@ -10,6 +10,6 @@ iCal - + diff --git a/Resources/Private/Templates/Calendar/Past.html b/Resources/Private/Templates/Calendar/Past.html index 70666f6d..1588c786 100644 --- a/Resources/Private/Templates/Calendar/Past.html +++ b/Resources/Private/Templates/Calendar/Past.html @@ -12,6 +12,6 @@ Atom iCal - + diff --git a/Resources/Private/Templates/Calendar/Result.html b/Resources/Private/Templates/Calendar/Result.html index 48e3e3bf..48ee0df2 100644 --- a/Resources/Private/Templates/Calendar/Result.html +++ b/Resources/Private/Templates/Calendar/Result.html @@ -1,5 +1,5 @@ - + diff --git a/Resources/Private/Templates/Calendar/Shortcut.html b/Resources/Private/Templates/Calendar/Shortcut.html index 98a3f6dc..fdb44890 100644 --- a/Resources/Private/Templates/Calendar/Shortcut.html +++ b/Resources/Private/Templates/Calendar/Shortcut.html @@ -4,6 +4,6 @@ - + diff --git a/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html b/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html index d6e96460..0cd5b4fa 100644 --- a/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html +++ b/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html @@ -1,3 +1,4 @@ +DEPRECATED: Use new pagination logic; remove file after Typo3 > 10 diff --git a/composer.json b/composer.json index 6328718c..b69f9b82 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,8 @@ "issues": "https://github.com/lochmueller/calendarize/issues" }, "suggest": { - "brotkrueml/schema": "Output of structured data information for better Google Search Result User Experience" + "brotkrueml/schema": "Output of structured data information for better Google Search Result User Experience", + "georgringer/numbered-pagination": "Pagination with reduced amount of pages" }, "require-dev": { "typo3/testing-framework": "^6.3",