Skip to content
Snippets Groups Projects
Commit b4cbcb86 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[BUGFIX] Fix problems with the pagebrowser

parent 484f668c
No related branches found
No related tags found
2 merge requests!33[BUGFIX] Fix totally broken page browser implementation, Cleanup code / Remove...,!32[TASK] Change the PageBrowser to not use a Controller and TypoScript
This commit is part of merge request !32. Comments created here will be created in the context of that merge request.
...@@ -70,13 +70,18 @@ class PageBrowserViewHelper extends AbstractViewHelper { ...@@ -70,13 +70,18 @@ class PageBrowserViewHelper extends AbstractViewHelper {
$view->setLayoutRootPaths($configuration['view.']['layoutRootPaths.']); $view->setLayoutRootPaths($configuration['view.']['layoutRootPaths.']);
$view->setTemplate('PageBrowser/Index'); $view->setTemplate('PageBrowser/Index');
$pageBrowserVars = GeneralUtility::_GP('tx_sgnews_pagebrowser'); $pageBrowserVars = GeneralUtility::_GP('tx_sgnews_pagebrowser');
$currentPage = $pageBrowserVars['currentPage']; if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) {
$currentPage = (int) $pageBrowserVars['currentPage'];
} else {
$currentPage = 1;
}
$pageLinks = []; $pageLinks = [];
$start = \max($currentPage - 1, 0); $start = 1;
$end = \min($this->arguments['numberOfPages'], $currentPage + 1 + 1); $end = $this->arguments['numberOfPages'];
for ($i = $start; $i < $end; $i++) { for ($i = $start; $i < $end; $i++) {
$pageLinks[] = [ $pageLinks[] = [
'number' => $i + 1, 'number' => $i,
'isCurrentPage' => $i === $currentPage, 'isCurrentPage' => $i === $currentPage,
]; ];
} }
...@@ -86,10 +91,11 @@ class PageBrowserViewHelper extends AbstractViewHelper { ...@@ -86,10 +91,11 @@ class PageBrowserViewHelper extends AbstractViewHelper {
'enableLessPages' => 1, 'enableLessPages' => 1,
'enableMorePages' => 1, 'enableMorePages' => 1,
'pageLinks' => $pageLinks, 'pageLinks' => $pageLinks,
'prevPageExist' => $currentPage > 0, 'currentPage' => $currentPage,
'showLessPages' => ($currentPage - 1) > 0, 'prevPageExist' => $currentPage > 1,
'showNextPages' => ($currentPage + 1 + 1) < $this->arguments['numberOfPages'], 'showLessPages' => ($currentPage - 1) > 1,
'nextPageExist' => $currentPage < ($this->arguments['numberOfPages'] - 1), 'showNextPages' => ($currentPage + 1) < $this->arguments['numberOfPages'],
'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1,
'numberOfPages' => $this->arguments['numberOfPages'] 'numberOfPages' => $this->arguments['numberOfPages']
] ]
); );
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
<f:section name="main"> <f:section name="main">
<nav> <nav>
<f:debug>{_all}</f:debug>
<ul class="pagination"> <ul class="pagination">
<f:if condition="{prevPageExist}"> <f:if condition="{prevPageExist}">
<f:then> <f:then>
<li class="tx-pagebrowse-prev"> <li class="tx-pagebrowse-prev">
<f:link.action action="index" <f:variable name="prevPage" value="{currentPage - 1}" />
additionalParams="{currentPage: '{pageLink.number} - 1'}" <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: prevPage}}"
additionalAttributes="{aria-label: 'Previous'}"> additionalAttributes="{aria-label: 'Previous'}">
&laquo; &laquo;
</f:link.action> </f:link.action>
...@@ -28,7 +29,8 @@ ...@@ -28,7 +29,8 @@
<f:if condition="{enableLessPages} && {showLessPages}"> <f:if condition="{enableLessPages} && {showLessPages}">
<li> <li>
<f:link.action action="index" additionalParams="{currentPage: '{pageLink.number} - 2'}"> <f:variable name="lessPage" value="{currentPage - 2}" />
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: lessPage}}">
... ...
</f:link.action> </f:link.action>
</li> </li>
...@@ -48,7 +50,7 @@ ...@@ -48,7 +50,7 @@
</f:then> </f:then>
<f:else> <f:else>
<li class="tx-pagebrowse-page"> <li class="tx-pagebrowse-page">
<f:link.action action="index" additionalParams="{currentPage: pageLink.number}"> <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: pageLink.number}}">
{pageLink.number} {pageLink.number}
</f:link.action> </f:link.action>
</li> </li>
...@@ -58,7 +60,8 @@ ...@@ -58,7 +60,8 @@
<f:if condition="{enableMorePages} && {showNextPages}"> <f:if condition="{enableMorePages} && {showNextPages}">
<li> <li>
<f:link.action action="index" additionalParams="{currentPage: '{pageLink.number} + 2'}"> <f:variable name="morePage" value="{currentPage + 2}" />
<f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: morePage}}">
... ...
</f:link.action> </f:link.action>
</li> </li>
...@@ -67,8 +70,8 @@ ...@@ -67,8 +70,8 @@
<f:if condition="{nextPageExist}"> <f:if condition="{nextPageExist}">
<f:then> <f:then>
<li class="tx-pagebrowse-next"> <li class="tx-pagebrowse-next">
<f:link.action action="index" <f:variable name="nextPage" value="{currentPage + 1}" />
additionalParams="{currentPage: '{pageLink.number} + 1'}" <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: nextPage}}"
additionalAttributes="{aria-label: 'Next'}"> additionalAttributes="{aria-label: 'Next'}">
&raquo; &raquo;
</f:link.action> </f:link.action>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment