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

[BUGFIX] Fix wrong counting of next and prev buttons

parent 9dbf9234
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
......@@ -26,6 +26,7 @@ namespace SGalinski\SgNews\ViewHelpers;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
......@@ -62,12 +63,13 @@ class PageBrowserViewHelper extends AbstractViewHelper {
* @throws \UnexpectedValueException
*/
public function render(): string {
$configuration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgnews.'];
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$configuration = $typoScriptService->convertTypoScriptArrayToPlainArray($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgnews.']);
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setRenderingContext($this->renderingContext);
$view->setTemplateRootPaths($configuration['view.']['templateRootPaths.']);
$view->setPartialRootPaths($configuration['view.']['partialRootPaths.']);
$view->setLayoutRootPaths($configuration['view.']['layoutRootPaths.']);
$view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$view->setPartialRootPaths($configuration['view']['partialRootPaths']);
$view->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
$view->setTemplate('PageBrowser/Index');
$pageBrowserVars = GeneralUtility::_GP('tx_sgnews_pagebrowser');
if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) {
......@@ -77,8 +79,8 @@ class PageBrowserViewHelper extends AbstractViewHelper {
}
$pageLinks = [];
$start = 1;
$end = $this->arguments['numberOfPages'];
$start = \max($currentPage - 1, 1);
$end = \min($this->arguments['numberOfPages'], $currentPage + 2);
for ($i = $start; $i < $end; $i++) {
$pageLinks[] = [
'number' => $i,
......@@ -94,7 +96,7 @@ class PageBrowserViewHelper extends AbstractViewHelper {
'currentPage' => $currentPage,
'prevPageExist' => $currentPage > 1,
'showLessPages' => ($currentPage - 1) > 1,
'showNextPages' => ($currentPage + 1) < $this->arguments['numberOfPages'],
'showNextPages' => ($currentPage + 2) < $this->arguments['numberOfPages'],
'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1,
'numberOfPages' => $this->arguments['numberOfPages']
]
......
......@@ -66,17 +66,14 @@ plugin.tx_sgnews {
view {
templateRootPaths {
0 = {$plugin.tx_sgnews.view.templateRootPath}
1 =
}
partialRootPaths {
0 = {$plugin.tx_sgnews.view.partialRootPath}
1 =
}
layoutRootPaths {
0 = {$plugin.tx_sgnews.view.layoutRootPath}
1 =
}
}
......
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