Skip to content

Commit 6ec2c3c

Browse files
author
Marvin Kuhn
committed
feature: added setting to always show the previous and next links
1 parent dd50ff0 commit 6ec2c3c

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

Classes/Fusion/PaginationArrayImplementation.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ protected function getPageArray()
9696
*/
9797
protected function addItemToTheStartOfPageArray($pageArray, $page, $type)
9898
{
99-
if ($this->firstPage > 1) {
100-
array_unshift($pageArray, [
101-
'page' => $page,
102-
'label' => $this->paginationConfig['labels'][$type],
103-
'type' => $type
104-
]);
105-
}
99+
array_unshift($pageArray, [
100+
'page' => $page,
101+
'label' => $this->paginationConfig['labels'][$type],
102+
'type' => $type
103+
]);
106104

107105
return $pageArray;
108106
}
@@ -116,13 +114,11 @@ protected function addItemToTheStartOfPageArray($pageArray, $page, $type)
116114
*/
117115
protected function addItemToTheEndOfPageArray($pageArray, $page, $type)
118116
{
119-
if ($this->lastPage < $this->numberOfPages) {
120-
$pageArray[] = [
121-
'page' => $page,
122-
'label' => $this->paginationConfig['labels'][$type],
123-
'type' => $type
124-
];
125-
}
117+
$pageArray[] = [
118+
'page' => $page,
119+
'label' => $this->paginationConfig['labels'][$type],
120+
'type' => $type
121+
];
126122

127123
return $pageArray;
128124
}
@@ -136,18 +132,31 @@ public function evaluate()
136132
}
137133

138134
$pageArray = $this->getPageArray();
139-
135+
// add seperators
140136
if ($this->paginationConfig['showSeperators']) {
141-
$pageArray = $this->addItemToTheStartOfPageArray($pageArray, false, 'seperator');
142-
$pageArray = $this->addItemToTheEndOfPageArray($pageArray, false, 'seperator');
137+
if ($this->firstPage > 1) {
138+
$pageArray = $this->addItemToTheStartOfPageArray($pageArray, false, 'seperator');
139+
}
140+
if ($this->lastPage < $this->numberOfPages) {
141+
$pageArray = $this->addItemToTheEndOfPageArray($pageArray, false, 'seperator');
142+
}
143143
}
144+
// add previous and next
144145
if ($this->paginationConfig['showNextAndPrevious']) {
145-
$pageArray = $this->addItemToTheStartOfPageArray($pageArray, $this->currentPage - 1, 'previous');
146-
$pageArray = $this->addItemToTheEndOfPageArray($pageArray, $this->currentPage + 1, 'next');
146+
if ($this->firstPage > 1 || $this->paginationConfig['alwaysShowNextAndPrevious']) {
147+
$pageArray = $this->addItemToTheStartOfPageArray($pageArray, $this->currentPage - 1, 'previous');
148+
}
149+
if ($this->lastPage < $this->numberOfPages || $this->paginationConfig['alwaysShowNextAndPrevious']) {
150+
$pageArray = $this->addItemToTheEndOfPageArray($pageArray, $this->currentPage + 1, 'next');
151+
}
147152
}
148153
if ($this->paginationConfig['showFirstAndLast']) {
149-
$pageArray = $this->addItemToTheStartOfPageArray($pageArray, 1, 'first');
150-
$pageArray = $this->addItemToTheEndOfPageArray($pageArray, $this->numberOfPages, 'last');
154+
if ($this->firstPage > 1 || $this->paginationConfig['alwaysShowFirstAndLast']) {
155+
$pageArray = $this->addItemToTheStartOfPageArray($pageArray, 1, 'first');
156+
}
157+
if ($this->lastPage < $this->numberOfPages || $this->paginationConfig['alwaysShowFirstAndLast']) {
158+
$pageArray = $this->addItemToTheEndOfPageArray($pageArray, $this->numberOfPages, 'last');
159+
}
151160
}
152161
return $pageArray;
153162
}

Configuration/Settings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Breadlesscode:
2121
pagination:
2222
showSeperators: true
2323
showNextAndPrevious: true
24+
alwaysShowNextAndPrevious: false
2425
showFirstAndLast: true
26+
alwaysShowFirstAndLast: false
2527
labels:
2628
seperator: '&hellip;'
2729
previous: '&lang;'

Resources/Private/Fusion/Component/PaginationConfig.fusion

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
prototype(Breadlesscode.Listable:PaginationConfig) < prototype(Neos.Fusion:RawArray) {
22
showSeperators = ${ Configuration.setting('Breadlesscode.Listable.pagination.showSeperators') }
33
showNextAndPrevious = ${ Configuration.setting('Breadlesscode.Listable.pagination.showNextAndPrevious') }
4+
alwaysShowNextAndPrevious = ${ Configuration.setting('Breadlesscode.Listable.pagination.alwaysShowNextAndPrevious') }
45
showFirstAndLast = ${ Configuration.setting('Breadlesscode.Listable.pagination.showFirstAndLast') }
6+
alwaysShowFirstAndLast = ${ Configuration.setting('Breadlesscode.Listable.pagination.alwaysShowFirstAndLast') }
57

68
labels = Neos.Fusion:RawArray {
79
seperator = ${ Configuration.setting('Breadlesscode.Listable.pagination.labels.seperator') }

0 commit comments

Comments
 (0)