Skip to content

Instantly share code, notes, and snippets.

@akiessling
Created February 10, 2025 22:55
Show Gist options
  • Select an option

  • Save akiessling/41a39cbcb04948a5cfc01cd3b5380db3 to your computer and use it in GitHub Desktop.

Select an option

Save akiessling/41a39cbcb04948a5cfc01cd3b5380db3 to your computer and use it in GitHub Desktop.
Forwardable paging arguments
<?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;
}
}
<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