Created
February 10, 2025 22:55
-
-
Save akiessling/41a39cbcb04948a5cfc01cd3b5380db3 to your computer and use it in GitHub Desktop.
Forwardable paging arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| namespace Vendor\Project\ViewHelpers; | |
| use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | |
| class ForwardablePagingArgumentsViewHelper extends \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper | |
| { | |
| public function initializeArguments() | |
| { | |
| // this is what you would usually set for the f:uri.action | |
| $this->registerArgument('arguments', 'array', 'Arguments to forward', false); | |
| // and this is taken from the current request | |
| $this->registerArgument('parameterToForward', 'string', 'Parameter to forward', true, ''); | |
| } | |
| public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) | |
| { | |
| $argumentsForUriBuilder = []; | |
| /** @var \TYPO3\CMS\Extbase\Mvc\Request $request */ | |
| $request = $renderingContext->getRequest(); | |
| if (isset($arguments['parameterToForward']) && $request->hasArgument($arguments['parameterToForward'])) { | |
| $argumentsForUriBuilder[$arguments['parameterToForward']] = $request->getArgument($arguments['parameterToForward']); | |
| } | |
| if ($arguments['arguments']) { | |
| $argumentsForUriBuilder = array_merge($argumentsForUriBuilder, $arguments['arguments']); | |
| } | |
| return $argumentsForUriBuilder; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <f:for each="{pagination.allPageNumbers}" as="page"> | |
| <li class="{f:if(condition: '{page} == {paginator.currentPageNumber}', then:'current')}"> | |
| <f:link.action arguments="{self:forwardablePagingArguments(arguments: '{currentPage: page}', parameterToForward: 'search')}">{page}</f:link.action> | |
| </li> | |
| </f:for> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment