Skip to content

Commit

Permalink
Replace pagination widget in FE list
Browse files Browse the repository at this point in the history
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: lochmueller#542
  • Loading branch information
okmiim committed May 8, 2021
1 parent 7483603 commit 82c5da1
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 19 deletions.
41 changes: 40 additions & 1 deletion Classes/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -141,6 +145,7 @@ public function latestAction(

$this->slotExtendedAssignMultiple([
'indices' => $search['indices'],
'pagination' => $this->getPagination($search['indices']),
'searchMode' => $search['searchMode'],
'searchParameter' => [
'startDate' => $startDate,
Expand Down Expand Up @@ -190,6 +195,7 @@ public function resultAction(

$this->slotExtendedAssignMultiple([
'indices' => $search['indices'],
'pagination' => $this->getPagination($search['indices']),
'searchMode' => $search['searchMode'],
'searchParameter' => [
'startDate' => $startDate,
Expand Down Expand Up @@ -241,6 +247,7 @@ public function listAction(

$this->slotExtendedAssignMultiple([
'indices' => $search['indices'],
'pagination' => $this->getPagination($search['indices']),
'searchMode' => $search['searchMode'],
'searchParameter' => [
'startDate' => $startDate,
Expand Down Expand Up @@ -287,6 +294,7 @@ public function shortcutAction()
}

$this->view->assignMultiple([
'pagination' => $this->getPagination($fetchEvent),
'indices' => $fetchEvent,
]);
}
Expand All @@ -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__);
}

Expand Down Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
20 changes: 8 additions & 12 deletions Resources/Private/Partials/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@
</f:for>
</f:then>
<f:else>
<f:if condition="{settings.paginateConfiguration}">
<f:then>
<f:widget.paginate objects="{indices}" as="paginatedIndices"
configuration="{settings.paginateConfiguration}">
<f:for each="{paginatedIndices}" as="index">
<f:render partial="{index.configuration.partialIdentifier}/ListItem" arguments="{index: index}"/>
</f:for>
</f:widget.paginate>
</f:then>
<f:else>
You have to include the static typoscript to get the paginateConfiguration for list views
</f:else>
<f:if condition="{settings.paginateConfiguration.insertAbove -> f:or(alternative:0)}">
<f:render partial="Pagination" arguments="{pagination: pagination.pagination, paginator: pagination.paginator}" />
</f:if>
<f:for each="{pagination.paginator.paginatedItems}" as="index">
<f:render partial="{index.configuration.partialIdentifier}/ListItem" arguments="{index: index}" />
</f:for>
<f:if condition="{settings.paginateConfiguration.insertBelow -> f:or(alternative:1)}">
<f:render partial="Pagination" arguments="{pagination: pagination.pagination, paginator: pagination.paginator}" />
</f:if>
</f:else>
</f:if>
Expand Down
57 changes: 57 additions & 0 deletions Resources/Private/Partials/Pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<ul class="f3-widget-paginator">
<f:if condition="{pagination.previousPageNumber} && {pagination.previousPageNumber} >= {pagination.firstPageNumber}">
<f:then>
<f:comment>
<li class="first">
<a href="{f:uri.action(action:actionName, arguments:{currentPage: 1})}" title="{f:translate(key:'pagination.first')}">
<i class="material-icons">first_page</i>
</a>
</li>
</f:comment>
<li class="previous">
<a href="{f:uri.action(action:actionName, arguments:{currentPage: pagination.previousPageNumber})}" title="{f:translate(key:'pagination.previous')}">
{f:translate(key:'widget.pagination.previous', extensionName: 'fluid')}
</a>
</li>
</f:then>
<f:else>
<f:comment>
<li class="disabled"><span><i class="material-icons">first_page</i></span></li>
<li class="disabled"><span>{f:translate(key:'widget.pagination.previous', extensionName: 'fluid')}</span></li>
</f:comment>
</f:else>
</f:if>
<f:if condition="{pagination.hasLessPages}">
<li></li>
</f:if>
<f:for each="{pagination.allPageNumbers}" as="page">
<li class="{f:if(condition: '{page} == {paginator.currentPageNumber}', then:'current')}">
<a href="{f:uri.action(action:actionName, arguments:{currentPage: page})}">{page}</a>
</li>
</f:for>
<f:if condition="{pagination.hasMorePages}">
<li></li>
</f:if>
<f:if condition="{pagination.nextPageNumber} && {pagination.nextPageNumber} <= {pagination.lastPageNumber}">
<f:then>
<li class="next">
<a href="{f:uri.action(action:actionName, arguments:{currentPage: pagination.nextPageNumber})}" title="{f:translate(key:'pagination.next')}">
{f:translate(key:'widget.pagination.next', extensionName: 'fluid')}
</a>
</li>
<f:comment>
<li class="last">
<a href="{f:uri.action(action:actionName, arguments:{currentPage: pagination.lastPageNumber})}" title="{f:translate(key:'pagination.last')}">
last
</a>
</li>
</f:comment>
</f:then>
<f:else>
<f:comment>
<li class="disabled"><span>{f:translate(key:'widget.pagination.next', extensionName: 'fluid')}</span></li>
<li class="disabled"><span>last page</span></li>
</f:comment>
</f:else>
</f:if>
</ul>
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Calendar/Latest.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<f:section name="Main">

<f:render partial="List" arguments="{settings: settings, indices: indices, contentObject:contentObject}" />
<f:render partial="List" arguments="{settings: settings, indices: indices, contentObject:contentObject, pagination: pagination}" />

</f:section>
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Calendar/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<f:link.action action="list" format="ics" arguments="{hmac: extended.pluginHmac}">iCal</f:link.action>
</f:comment>

<f:render partial="List" arguments="{settings: settings, indices: indices, contentObject:contentObject}" />
<f:render partial="List" arguments="{settings: settings, indices: indices, contentObject:contentObject, pagination: pagination}" />

</f:section>
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Calendar/Past.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<f:link.action action="list" format="atom" arguments="{hmac: extended.pluginHmac}">Atom</f:link.action>
<f:link.action action="list" format="ics" arguments="{hmac: extended.pluginHmac}">iCal</f:link.action>
</f:comment>
<f:render partial="List" arguments="{settings: settings, indices: indices,contentObject:contentObject}" />
<f:render partial="List" arguments="{settings: settings, indices: indices,contentObject:contentObject, pagination: pagination}" />

</f:section>
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Calendar/Result.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<f:layout name="Default" />

<f:section name="Main">
<f:render partial="List" arguments="{settings: settings, indices: indices, searchParameter: searchParameter, searchMode: searchMode,contentObject:contentObject}" />
<f:render partial="List" arguments="{settings: settings, indices: indices, searchParameter: searchParameter, searchMode: searchMode,contentObject:contentObject, pagination: pagination}" />
</f:section>
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Calendar/Shortcut.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<f:flashMessages />

<f:render partial="List" arguments="{settings: settings, indices: indices,contentObject:contentObject}" />
<f:render partial="List" arguments="{settings: settings, indices: indices,contentObject:contentObject, pagination: pagination}" />

</f:section>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<f:comment>DEPRECATED: Use new pagination logic; remove file after Typo3 > 10</f:comment>
<f:if condition="{configuration.insertAbove}">
<f:render section="paginator" arguments="{pagination: pagination, configuration: configuration}" />
</f:if>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 82c5da1

Please sign in to comment.