Project

General

Profile

Actions

Feature #81814

closed

Allow additional arguments for Fluid's widget.paginate view helper

Added by Tobias Schmidt almost 7 years ago. Updated about 4 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2017-07-06
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Fluid, ViewHelper, Pagination, Page Browser
Complexity:
Sprint Focus:

Description

The current version of Fluid's widget.paginate ViewHelper does not allow adding additional arguments to page links. This prevents the use of the widget in combination with a search filter for example. Filter values send with method GET or POST are not added to the query string of page links and are lost when browsing result pages.

One could set addQueryStringMethod: GET,POST in paginate's configuration array to add all field values of the current request to the query string. But this includes the hidden __referrer fields of Extbase for example which should not be part of the query string of page links.

There should be a way to tell the paginate widget precisely which arguments to add to the query string of page links. This requires changes not only in the paginate widget but also in the link widget which is used by the paginate widget to create page links.

Here's my suggestion:

Usage of paginate widget

<f:widget.paginate objects="{myObjects}" as="myPaginatedObjects" additionalArgumentsPrefix="tx_myext_pi1[filter]" additionalArguments="{searchTerm: filter.searchTerm, category: filter.category}">

Changes in Classes/ViewHelpers/Widget/PaginateViewHelper.php

Register arguments in method initializeArguments:

$this->registerArgument('AdditionalArgumentsPrefix', 'string', 'Prefix of additional arguments', false);
$this->registerArgument('AdditionalArguments', 'array', 'Additional arguments', false);

Change in Classes/ViewHelpers/Widget/Controller/PaginateController.php

Add class variables:

/**
 * @var string
 */
protected $additionalArgumentsPrefix;

/**
 * @var array
 */
protected $additionalArguments;

Add default values to $configuration:

/**
 * @var array
 */
protected $configuration = [
    'itemsPerPage' => 10,
    'insertAbove' => false,
    'insertBelow' => true,
    'maximumNumberOfLinks' => 99,
    'addQueryStringMethod' => '',
    'section' => '',
    'additionalArgumentsPrefix' => '',
    'additionalArguments' => '',
];

Initialize arguments in method initializeAction:

$this->additionalArgumentsPrefix = $this->widgetConfiguration['additionalArgumentsPrefix'];
$this->additionalArguments = $this->widgetConfiguration['additionalArguments'];

Assign arguments to view in method indexAction:

$this->view->assign('additionalArgumentsPrefix', $this->additionalArgumentsPrefix);
$this->view->assign('additionalArguments', $this->additionalArguments);

Changes in Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html

Add arguments to render ViewHelpers of insertAbove and insertBelow:

<f:render section="paginator" arguments="{pagination: pagination, additionalArgumentsPrefix: additionalArgumentsPrefix, additionalArguments: additionalArguments, configuration:configuration}" />

Add arguments to all usages of the widget link ViewHelper:

<f:widget.link arguments="{currentPage: page.number}" addQueryStringMethod="{configuration.addQueryStringMethod}" additionalArgumentsPrefix="{additionalArgumentsPrefix}" additionalArguments="{additionalArguments}"  section="{configuration.section}">{page.number}</f:widget.link>

Changes to Classes/ViewHelpers/Widget/LinkViewHelper.php

Add arguments to method render:

/**
 * Render the link.
 *
 * @param string $action Target action
 * @param array $arguments Arguments
 * @param string $section The anchor to be added to the URI
 * @param string $format The requested format, e.g. ".html
 * @param bool $ajax TRUE if the URI should be to an AJAX widget, FALSE otherwise.
 * @param string $additionalArgumentsPrefix
 * @param array $additionalArguments
 * @return string The rendered link
 * @api
 */
public function render($action = null, $arguments = [], $section = '', $format = '', $ajax = false, $additionalArgumentsPrefix = '', $additionalArguments = [])
{

Add arguments in method getAjaxUri:

$additionalArgumentsPrefix = $this->arguments['additionalArgumentsPrefix'];
$additionalArguments = $this->arguments['additionalArguments'];
$arguments[$additionalArgumentsPrefix] = $additionalArguments;

Add arguments in method getWidgetUri:

$additionalArgumentsPrefix = $this->hasArgument('additionalArgumentsPrefix') ? $this->arguments['additionalArgumentsPrefix'] : '';
$additionalArguments = $this->hasArgument('additionalArguments') ? $this->arguments['additionalArguments'] : [];

Add arguments to UriBuilder call in method getWidgetUri:

return $uriBuilder->reset()
    ->setArguments([$argumentPrefix => $arguments, $additionalArgumentsPrefix => $additionalArguments])
    ->setSection($this->arguments['section'])
    ->setAddQueryString(true)
    ->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])
    ->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
    ->setFormat($this->arguments['format'])
    ->build();

That's it. I see at least two problems with this solution. First there could be a conflict between addQueryStringMethod and additional arguments. Second there ist only one prefix possible. So this is not supposed to be a perfect but a somehow working solution. What do you think of it?

Actions

Also available in: Atom PDF