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
This commit is part of merge request !32. Comments created here will be created in the context of that merge request.
...@@ -26,6 +26,7 @@ namespace SGalinski\SgNews\ViewHelpers; ...@@ -26,6 +26,7 @@ namespace SGalinski\SgNews\ViewHelpers;
* This copyright notice MUST APPEAR in all copies of the script! * 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\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView; use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
...@@ -62,12 +63,13 @@ class PageBrowserViewHelper extends AbstractViewHelper { ...@@ -62,12 +63,13 @@ class PageBrowserViewHelper extends AbstractViewHelper {
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
public function render(): string { 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 = GeneralUtility::makeInstance(StandaloneView::class);
$view->setRenderingContext($this->renderingContext); $view->setRenderingContext($this->renderingContext);
$view->setTemplateRootPaths($configuration['view.']['templateRootPaths.']); $view->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$view->setPartialRootPaths($configuration['view.']['partialRootPaths.']); $view->setPartialRootPaths($configuration['view']['partialRootPaths']);
$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');
if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) { if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) {
...@@ -77,8 +79,8 @@ class PageBrowserViewHelper extends AbstractViewHelper { ...@@ -77,8 +79,8 @@ class PageBrowserViewHelper extends AbstractViewHelper {
} }
$pageLinks = []; $pageLinks = [];
$start = 1; $start = \max($currentPage - 1, 1);
$end = $this->arguments['numberOfPages']; $end = \min($this->arguments['numberOfPages'], $currentPage + 2);
for ($i = $start; $i < $end; $i++) { for ($i = $start; $i < $end; $i++) {
$pageLinks[] = [ $pageLinks[] = [
'number' => $i, 'number' => $i,
...@@ -94,7 +96,7 @@ class PageBrowserViewHelper extends AbstractViewHelper { ...@@ -94,7 +96,7 @@ class PageBrowserViewHelper extends AbstractViewHelper {
'currentPage' => $currentPage, 'currentPage' => $currentPage,
'prevPageExist' => $currentPage > 1, 'prevPageExist' => $currentPage > 1,
'showLessPages' => ($currentPage - 1) > 1, 'showLessPages' => ($currentPage - 1) > 1,
'showNextPages' => ($currentPage + 1) < $this->arguments['numberOfPages'], 'showNextPages' => ($currentPage + 2) < $this->arguments['numberOfPages'],
'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1, 'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1,
'numberOfPages' => $this->arguments['numberOfPages'] 'numberOfPages' => $this->arguments['numberOfPages']
] ]
......
...@@ -66,17 +66,14 @@ plugin.tx_sgnews { ...@@ -66,17 +66,14 @@ plugin.tx_sgnews {
view { view {
templateRootPaths { templateRootPaths {
0 = {$plugin.tx_sgnews.view.templateRootPath} 0 = {$plugin.tx_sgnews.view.templateRootPath}
1 =
} }
partialRootPaths { partialRootPaths {
0 = {$plugin.tx_sgnews.view.partialRootPath} 0 = {$plugin.tx_sgnews.view.partialRootPath}
1 =
} }
layoutRootPaths { layoutRootPaths {
0 = {$plugin.tx_sgnews.view.layoutRootPath} 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