diff --git a/Classes/Controller/PageBrowserController.php b/Classes/Controller/PageBrowserController.php deleted file mode 100644 index 42f0a5f1848d705285b595b2f660e55f3c2ef74e..0000000000000000000000000000000000000000 --- a/Classes/Controller/PageBrowserController.php +++ /dev/null @@ -1,146 +0,0 @@ -<?php - -namespace SGalinski\SgJobs\Controller; - -/*************************************************************** - * Copyright notice - * - * (c) sgalinski Internet Services (https://www.sgalinski.de) - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; - -/** - * Controller that handles the page browser. - */ -class PageBrowserController extends ActionController { - /** - * @var string - */ - protected $pageParameterName = ''; - - /** - * @var int - */ - protected $numberOfPages = 0; - - /** - * @var int - */ - protected $currentPage = 0; - - /** - * @var int - */ - protected $pagesBefore = 0; - - /** - * @var int - */ - protected $pagesAfter = 0; - - /** - * @var bool - */ - protected $enableMorePages = FALSE; - - /** - * @var bool - */ - protected $enableLessPages = FALSE; - - /** - * Renders the index view. - * - * @param int $currentPage - * @return void - */ - public function indexAction($currentPage = 0): void { - $this->currentPage = (int) $currentPage; - - $this->initializeConfiguration(); - $this->addDataToView(); - } - - /** - * Initializes the configuration. - * - * @return void - */ - protected function initializeConfiguration(): void { - $this->pageParameterName = 'tx_sgjobs_pagebrowser[currentPage]'; - $this->numberOfPages = (int) $this->settings['numberOfPages']; - $this->pagesBefore = (int) $this->settings['pagesBefore']; - $this->pagesAfter = (int) $this->settings['pagesAfter']; - $this->enableMorePages = (bool) $this->settings['enableMorePages']; - $this->enableLessPages = (bool) $this->settings['enableLessPages']; - } - - /** - * Adds the necessary data to the view. - * - * @return void - */ - protected function addDataToView(): void { - if ($this->numberOfPages <= 1) { - $this->view = NULL; - return; - } - - $pageLinks = []; - $start = max($this->currentPage - $this->pagesBefore, 0); - $end = min($this->numberOfPages, $this->currentPage + $this->pagesAfter + 1); - for ($i = $start; $i < $end; $i++) { - $pageLinks[] = [ - 'number' => $i + 1, - 'link' => $this->getPageLink($i), - 'isCurrentPage' => $i === $this->currentPage, - ]; - } - - $this->view->assignMultiple( - [ - 'enableLessPages' => $this->enableLessPages, - 'enableMorePages' => $this->enableMorePages, - 'previousLink' => $this->getPageLink($this->currentPage - 1), - 'nextLink' => $this->getPageLink($this->currentPage + 1), - 'enableLessPagesLink' => $this->getPageLink($this->currentPage - $this->pagesBefore - 1), - 'enableMorePagesLink' => $this->getPageLink($this->currentPage + $this->pagesAfter + 1), - 'pageLinks' => $pageLinks, - 'prevPageExist' => $this->currentPage > 0, - 'showLessPages' => ($this->currentPage - $this->pagesBefore) > 0, - 'showNextPages' => ($this->currentPage + $this->pagesAfter + 1) < $this->numberOfPages, - 'nextPageExist' => $this->currentPage < ($this->numberOfPages - 1), - ] - ); - } - - /** - * Generates page link. Keeps all current URL parameters except for cHash and tx_pagebrowse_pi1[page]. - * - * @param int $page Page number starting from 1 - * @return string - */ - protected function getPageLink($page): string { - return $this->uriBuilder->reset()->setAddQueryString(TRUE) - ->uriFor('index', ['currentPage' => $page,]); - } -} diff --git a/Classes/ViewHelpers/PageBrowserViewHelper.php b/Classes/ViewHelpers/PageBrowserViewHelper.php index 495f9038bc64253432691aa3a9bb9a1a6fab463a..dd46580760627f5b47b7527ff5997dca115c324e 100644 --- a/Classes/ViewHelpers/PageBrowserViewHelper.php +++ b/Classes/ViewHelpers/PageBrowserViewHelper.php @@ -26,8 +26,10 @@ namespace SGalinski\SgJobs\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\Extbase\Object\ObjectManager; +use TYPO3\CMS\Fluid\View\StandaloneView; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; @@ -55,13 +57,44 @@ class PageBrowserViewHelper extends AbstractViewHelper { * @throws \UnexpectedValueException */ public function render(): string { - $configuration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgjobs.']['pagebrowser.']; - $configuration['settings.']['numberOfPages'] = (int) $this->arguments['numberOfPages']; + $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class); + $configuration = $typoScriptService->convertTypoScriptArrayToPlainArray($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_sgjobs.']); + $view = GeneralUtility::makeInstance(StandaloneView::class); + $view->setRenderingContext($this->renderingContext); + $view->setTemplate('PageBrowser/Index'); + $view->setTemplateRootPaths($configuration['view']['templateRootPaths']); + $view->setPartialRootPaths($configuration['view']['partialRootPaths']); + $view->setLayoutRootPaths($configuration['view']['layoutRootPaths']); + $pageBrowserVars = GeneralUtility::_GP('tx_sgnews_pagebrowser'); + if (isset($pageBrowserVars['currentPage']) && (int) $pageBrowserVars['currentPage'] > 0) { + $currentPage = (int) $pageBrowserVars['currentPage']; + } else { + $currentPage = 1; + } - /** @var ContentObjectRenderer $contentObject */ - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); - $contentObject = $objectManager->get(ContentObjectRenderer::class); - $contentObject->start([]); - return $contentObject->cObjGetSingle('USER', $configuration); + $pageLinks = []; + $start = \max($currentPage - 1, 1); + $end = \min($this->arguments['numberOfPages'], $currentPage + 2); + for ($i = $start; $i < $end; $i++) { + $pageLinks[] = [ + 'number' => $i, + 'isCurrentPage' => $i === $currentPage, + ]; + } + + $view->assignMultiple( + [ + 'enableLessPages' => 1, + 'enableMorePages' => 1, + 'pageLinks' => $pageLinks, + 'currentPage' => $currentPage, + 'prevPageExist' => $currentPage > 1, + 'showLessPages' => ($currentPage - 1) > 1, + 'showNextPages' => ($currentPage + 2) < $this->arguments['numberOfPages'], + 'nextPageExist' => $currentPage < $this->arguments['numberOfPages'] - 1, + 'numberOfPages' => $this->arguments['numberOfPages'] + ] + ); + return $view->render(); } } diff --git a/Configuration/TypoScript/Frontend/constants.typoscript b/Configuration/TypoScript/Frontend/constants.typoscript index e0f95ba9896846d07d55c8088a24e83b6428e2ef..426091157d9b670fda23d5359dff8ab3004da2ad 100644 --- a/Configuration/TypoScript/Frontend/constants.typoscript +++ b/Configuration/TypoScript/Frontend/constants.typoscript @@ -1,13 +1,13 @@ plugin.tx_sgjobs { view { # cat=plugin.tx_tx_extensionskeleton/file; type=string; label=Path to template root (FE) - templateRootPath = EXT:tx_sgjobs/Resources/Private/Templates/ + templateRootPath = EXT:sg_jobs/Resources/Private/Templates/ # cat=plugin.tx_tx_extensionskeleton/file; type=string; label=Path to template partials (FE) - partialRootPath = EXT:tx_sgjobs/Resources/Private/Partials/ + partialRootPath = EXT:sg_jobs/Resources/Private/Partials/ # cat=plugin.tx_tx_extensionskeleton/file; type=string; label=Path to template layouts (FE) - layoutRootPath = EXT:tx_sgjobs/Resources/Private/Layouts/ + layoutRootPath = EXT:sg_jobs/Resources/Private/Layouts/ } settings { diff --git a/Configuration/TypoScript/Frontend/setup.typoscript b/Configuration/TypoScript/Frontend/setup.typoscript index 9f0c1a20f1135014584f8b4ba15e2420f9221945..7bc2e71f1978b889e5d85d5fac1029135bf34cd6 100644 --- a/Configuration/TypoScript/Frontend/setup.typoscript +++ b/Configuration/TypoScript/Frontend/setup.typoscript @@ -2,17 +2,14 @@ plugin.tx_sgjobs { view { templateRootPaths { 0 = {$plugin.tx_sgjobs.view.templateRootPath} - 1 = } partialRootPaths { 0 = {$plugin.tx_sgjobs.view.partialRootPath} - 1 = } layoutRootPaths { 0 = {$plugin.tx_sgjobs.view.layoutRootPath} - 1 = } } @@ -37,41 +34,6 @@ plugin.tx_sgjobs { legacy { enableLegacyFlashMessageHandling = 0 } - - pagebrowser = USER - pagebrowser { - userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run - extensionName = SgJobs - pluginName = PageBrowser - vendorName = SGalinski - controller = PageBrowser - action = index - view < plugin.tx_sgjobs.view - persistence < plugin.tx_sgjobs.persistence - features < plugin.tx_sgjobs.features - # cHash can't be generated for pageBrowser call; will cause a 404 error if not set to 0 - features.requireCHashArgumentForActionArguments = 0 - legacy < plugin.tx_sgjobs.legacy - settings { - # Number of page links to show before the current page - pagesBefore = {$plugin.tx_sgjobs.pagebrowser.settings.pagesBefore} - - # Number of page links to show before the current page - pagesAfter = {$plugin.tx_sgjobs.pagebrowser.settings.pagesAfter} - - # Enables section for "more" pages. This section is shown after links to next pages, normally like three dots (1 2 3 ...). Notice that you can also hide it by emptying corresponding template section. - enableMorePages = {$plugin.tx_sgjobs.pagebrowser.settings.enableMorePages} - - # Enables section for "less" pages. This section is shown after links to next pages, normally like three dots (... 1 2 3) Notice that you can also hide it by emptying corresponding template section. - enableLessPages = {$plugin.tx_sgjobs.pagebrowser.settings.enableLessPages} - - # The number of the pages - numberOfPages = 0 - - # The current page - currentPage = 0 - } - } } config.recordLinks { diff --git a/Resources/Private/Templates/PageBrowser/Index.html b/Resources/Private/Templates/PageBrowser/Index.html index eac92ae96b0da3126679d4c02c9ce38a338c6e70..90600cdca33bb71c504dd2d4ac04ae7874fe3d7d 100644 --- a/Resources/Private/Templates/PageBrowser/Index.html +++ b/Resources/Private/Templates/PageBrowser/Index.html @@ -8,9 +8,11 @@ <f:if condition="{prevPageExist}"> <f:then> <li class="tx-pagebrowse-prev"> - <a href="{previousLink}" aria-label="Previous"> + <f:variable name="prevPage" value="{currentPage - 1}" /> + <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: prevPage}}" + additionalAttributes="{aria-label: 'Previous'}"> « - </a> + </f:link.action> </li> </f:then> <f:else> @@ -26,9 +28,10 @@ <f:if condition="{enableLessPages} && {showLessPages}"> <li> - <a href="{enableLessPagesLink}"> + <f:variable name="lessPage" value="{currentPage - 2}" /> + <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: lessPage}}"> ... - </a> + </f:link.action> </li> </f:if> @@ -46,9 +49,9 @@ </f:then> <f:else> <li class="tx-pagebrowse-page"> - <a href="{pageLink.link}"> + <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: pageLink.number}}"> {pageLink.number} - </a> + </f:link.action> </li> </f:else> </f:if> @@ -56,18 +59,21 @@ <f:if condition="{enableMorePages} && {showNextPages}"> <li> - <a href="{enableMorePagesLink}"> + <f:variable name="morePage" value="{currentPage + 2}" /> + <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: morePage}}"> ... - </a> + </f:link.action> </li> </f:if> <f:if condition="{nextPageExist}"> <f:then> <li class="tx-pagebrowse-next"> - <a href="{nextLink}" aria-label="Next"> + <f:variable name="nextPage" value="{currentPage + 1}" /> + <f:link.action additionalParams="{tx_sgnews_pagebrowser: {currentPage: nextPage}}" + additionalAttributes="{aria-label: 'Next'}"> » - </a> + </f:link.action> </li> </f:then> <f:else>