From c5b84cd8a3d26aa4c42dbdf10c80883010cc44ce Mon Sep 17 00:00:00 2001 From: Stanislas Rolland <typo3@sjbr.ca> Date: Fri, 19 Jul 2013 15:31:09 -0400 Subject: [PATCH] [FEATURE] uriBuilder should honor POST arguments for addQueryString Currently the addQueryString option in the uriBuilder only supports arguments which are in the query string. Therefore, the pagination widget does not work with filtering post requests. Solution: Add addQueryStringMethod (already supported by typolink configuration) as property of uriBuilder and as argument of the following fluid view helpers: * link.action * link.page * uri.action * uri.page * widget.link * widget.uri * widget.pagination Add addQueryStringMethod as configuration option of the paginate widget. Fixes: #35281 Fixes: #11441 Releases: 6.2 Change-Id: I8f2963fa7467dffcf3b9535d2a41820de8f9930a Reviewed-on: https://review.typo3.org/22432 Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring Reviewed-by: Stefano Cecere Reviewed-by: Stefan Neufeind Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../Classes/Mvc/Web/Routing/UriBuilder.php | 56 +++++++++++++- .../Unit/Mvc/Web/Routing/UriBuilderTest.php | 77 +++++++++++++++++-- .../ViewHelpers/Link/ActionViewHelper.php | 5 +- .../ViewHelpers/Link/PageViewHelper.php | 17 +++- .../ViewHelpers/Uri/ActionViewHelper.php | 5 +- .../ViewHelpers/Uri/PageViewHelper.php | 5 +- .../Widget/Controller/PaginateController.php | 2 +- .../ViewHelpers/Widget/LinkViewHelper.php | 6 +- .../ViewHelpers/Widget/UriViewHelper.php | 15 +++- .../ViewHelpers/Widget/Paginate/Index.html | 18 ++--- .../ViewHelpers/ViewHelperBaseTestcase.php | 1 + 11 files changed, 177 insertions(+), 30 deletions(-) diff --git a/typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php b/typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php index 56a3ab29a65b..89cb3721fede 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php +++ b/typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php @@ -76,6 +76,11 @@ class UriBuilder { */ protected $addQueryString = FALSE; + /** + * @var string + */ + protected $addQueryStringMethod = NULL; + /** * @var array */ @@ -270,6 +275,28 @@ class UriBuilder { return $this->addQueryString; } + /** + * Sets the method to get the addQueryString parameters. Defaults undefined + * which results in using QUERY_STRING. + * + * @param string $addQueryStringMethod + * @return Tx_Extbase_MVC_Web_Routing_UriBuilder the current UriBuilder to allow method chaining + * @api + * @see TSref/typolink.addQueryString.method + */ + public function setAddQueryStringMethod($addQueryStringMethod) { + $this->addQueryStringMethod = $addQueryStringMethod; + return $this; + } + + /** + * @return string + * @api + */ + public function getAddQueryStringMethod() { + return (string)$this->addQueryStringMethod; + } + /** * A list of arguments to be excluded from the query parameters * Only active if addQueryString is set @@ -436,6 +463,7 @@ class UriBuilder { $this->format = ''; $this->createAbsoluteUri = FALSE; $this->addQueryString = FALSE; + $this->addQueryStringMethod = NULL; $this->argumentsToBeExcludedFromQueryString = array(); $this->linkAccessRestrictedPages = FALSE; $this->targetPageUid = NULL; @@ -548,15 +576,34 @@ class UriBuilder { */ public function buildBackendUri() { if ($this->addQueryString === TRUE) { - $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET(); + if ($this->addQueryStringMethod) { + switch ($this->addQueryStringMethod) { + case 'GET': + $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET(); + break; + case 'POST': + $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST(); + break; + case 'GET,POST': + $arguments = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET(), \TYPO3\CMS\Core\Utility\GeneralUtility::_POST()); + break; + case 'POST,GET': + $arguments = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST(), \TYPO3\CMS\Core\Utility\GeneralUtility::_GET()); + break; + default: + $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('QUERY_STRING'), TRUE); + } + } else { + $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET(); + } foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { $argumentToBeExcluded = \TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array($argumentToBeExcluded, TRUE); $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::arrayDiffAssocRecursive($arguments, $argumentToBeExcluded); } } else { $arguments = array( - 'M' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('M'), - 'id' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id') + 'M' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('M'), + 'id' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id') ); } $arguments = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($arguments, $this->arguments); @@ -617,6 +664,9 @@ class UriBuilder { 'exclude' => implode(',', $this->argumentsToBeExcludedFromQueryString) ); } + if ($this->addQueryStringMethod) { + $typolinkConfiguration['addQueryString.']['method'] = $this->addQueryStringMethod; + } } if ($this->noCache === TRUE) { $typolinkConfiguration['no_cache'] = 1; diff --git a/typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php b/typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php index 6bff949a56ce..73729fe62fdc 100644 --- a/typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php @@ -42,6 +42,11 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { */ protected $getBackup; + /** + * @var array + */ + protected $postBackup; + /** * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */ @@ -71,6 +76,7 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { $this->tsfeBackup = $GLOBALS['TSFE']; $GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE); $this->getBackup = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET(); + $this->postBackup = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST(); $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $this->mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request'); $this->mockExtensionService = $this->getMock('TYPO3\\CMS\\Extbase\\Service\\ExtensionService'); @@ -86,13 +92,14 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { public function tearDown() { $GLOBALS['TSFE'] = $this->tsfeBackup; \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset($this->getBackup); + $_POST = $this->postBackup; } /** * @test */ public function settersAndGettersWorkAsExpected() { - $this->uriBuilder->reset()->setArguments(array('test' => 'arguments'))->setSection('testSection')->setFormat('testFormat')->setCreateAbsoluteUri(TRUE)->setAbsoluteUriScheme('https')->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(TRUE)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(TRUE)->setUseCacheHash(FALSE); + $this->uriBuilder->reset()->setArguments(array('test' => 'arguments'))->setSection('testSection')->setFormat('testFormat')->setCreateAbsoluteUri(TRUE)->setAbsoluteUriScheme('https')->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))->setAddQueryStringMethod('GET,POST')->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(TRUE)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(TRUE)->setUseCacheHash(FALSE); $this->assertEquals(array('test' => 'arguments'), $this->uriBuilder->getArguments()); $this->assertEquals('testSection', $this->uriBuilder->getSection()); $this->assertEquals('testFormat', $this->uriBuilder->getFormat()); @@ -100,6 +107,7 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { $this->assertEquals('https', $this->uriBuilder->getAbsoluteUriScheme()); $this->assertEquals(TRUE, $this->uriBuilder->getAddQueryString()); $this->assertEquals(array('test' => 'addQueryStringExcludeArguments'), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString()); + $this->assertEquals('GET,POST', $this->uriBuilder->getAddQueryStringMethod()); $this->assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix()); $this->assertEquals(TRUE, $this->uriBuilder->getLinkAccessRestrictedPages()); $this->assertEquals(123, $this->uriBuilder->getTargetPageUid()); @@ -189,7 +197,24 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { */ public function buildBackendUriKeepsQueryParametersIfAddQueryStringIsSet() { \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar')); + $_POST = array(); + $_POST['foo2'] = 'bar2'; + $this->uriBuilder->setAddQueryString(TRUE); + $this->uriBuilder->setAddQueryStringMethod('GET,POST'); + $expectedResult = 'mod.php?M=moduleKey&id=pageId&foo=bar&foo2=bar2'; + $actualResult = $this->uriBuilder->buildBackendUri(); + $this->assertEquals($expectedResult, $actualResult); + } + + /** + * @test + */ + public function buildBackendUriKeepsQueryParametersIfAddQueryStringMethodIsNotSet() { + \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('M' => 'moduleKey', 'id' => 'pageId', 'foo' => 'bar')); + $_POST = array(); + $_POST['foo2'] = 'bar2'; $this->uriBuilder->setAddQueryString(TRUE); + $this->uriBuilder->setAddQueryStringMethod(NULL); $expectedResult = 'mod.php?M=moduleKey&id=pageId&foo=bar'; $actualResult = $this->uriBuilder->buildBackendUri(); $this->assertEquals($expectedResult, $actualResult); @@ -206,11 +231,14 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { 'id' => 'pageId', 'foo' => 'bar' ), + array( + 'foo2' => 'bar2' + ), array( 'M', 'id' ), - 'mod.php?foo=bar' + 'mod.php?foo=bar&foo2=bar2' ), 'Arguments to be excluded in the end' => array( array( @@ -218,11 +246,14 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { 'id' => 'pageId', 'M' => 'moduleKey' ), + array( + 'foo2' => 'bar2' + ), array( 'M', 'id' ), - 'mod.php?foo=bar' + 'mod.php?foo=bar&foo2=bar2' ), 'Arguments in nested array to be excluded' => array( array( @@ -232,11 +263,14 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { 'id' => 'pageId', 'M' => 'moduleKey' ), + array( + 'foo2' => 'bar2' + ), array( 'id', 'tx_foo[bar]' ), - 'mod.php?M=moduleKey' + 'mod.php?M=moduleKey&foo2=bar2' ), 'Arguments in multidimensional array to be excluded' => array( array( @@ -248,11 +282,14 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { 'id' => 'pageId', 'M' => 'moduleKey' ), + array( + 'foo2' => 'bar2' + ), array( 'id', 'tx_foo[bar][baz]' ), - 'mod.php?M=moduleKey' + 'mod.php?M=moduleKey&foo2=bar2' ), ); } @@ -261,9 +298,11 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { * @test * @dataProvider buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSetDataProvider */ - public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet(array $parameters, array $excluded, $expected) { + public function buildBackendUriRemovesSpecifiedQueryParametersIfArgumentsToBeExcludedFromQueryStringIsSet(array $parameters, array $postArguments, array $excluded, $expected) { \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset($parameters); + $_POST = $postArguments; $this->uriBuilder->setAddQueryString(TRUE); + $this->uriBuilder->setAddQueryStringMethod('GET,POST'); $this->uriBuilder->setArgumentsToBeExcludedFromQueryString($excluded); $actualResult = $this->uriBuilder->buildBackendUri(); $this->assertEquals($expected, $actualResult); @@ -409,7 +448,7 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { * @test */ public function resetSetsAllOptionsToTheirDefaultValue() { - $this->uriBuilder->setArguments(array('test' => 'arguments'))->setSection('testSection')->setFormat('someFormat')->setCreateAbsoluteUri(TRUE)->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(TRUE)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(TRUE)->setUseCacheHash(FALSE); + $this->uriBuilder->setArguments(array('test' => 'arguments'))->setSection('testSection')->setFormat('someFormat')->setCreateAbsoluteUri(TRUE)->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array('test' => 'addQueryStringExcludeArguments'))->setAddQueryStringMethod(NULL)->setArgumentPrefix('testArgumentPrefix')->setLinkAccessRestrictedPages(TRUE)->setTargetPageUid(123)->setTargetPageType(321)->setNoCache(TRUE)->setUseCacheHash(FALSE); $this->uriBuilder->reset(); $this->assertEquals(array(), $this->uriBuilder->getArguments()); $this->assertEquals('', $this->uriBuilder->getSection()); @@ -417,6 +456,7 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { $this->assertEquals(FALSE, $this->uriBuilder->getCreateAbsoluteUri()); $this->assertEquals(FALSE, $this->uriBuilder->getAddQueryString()); $this->assertEquals(array(), $this->uriBuilder->getArgumentsToBeExcludedFromQueryString()); + $this->assertEquals(NULL, $this->uriBuilder->getAddQueryStringMethod()); $this->assertEquals(NULL, $this->uriBuilder->getArgumentPrefix()); $this->assertEquals(FALSE, $this->uriBuilder->getLinkAccessRestrictedPages()); $this->assertEquals(NULL, $this->uriBuilder->getTargetPageUid()); @@ -457,6 +497,29 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { $this->assertEquals($expectedConfiguration, $actualConfiguration); } + /** + * @test + */ + public function buildTypolinkConfigurationProperlySetsAddQueryString() { + $this->uriBuilder->setTargetPageUid(123); + $this->uriBuilder->setAddQueryString(TRUE); + $expectedConfiguration = array('parameter' => 123, 'addQueryString' => 1, 'useCacheHash' => 1); + $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration'); + $this->assertEquals($expectedConfiguration, $actualConfiguration); + } + + /** + * @test + */ + public function buildTypolinkConfigurationProperlySetsAddQueryStringMethod() { + $this->uriBuilder->setTargetPageUid(123); + $this->uriBuilder->setAddQueryString(TRUE); + $this->uriBuilder->setAddQueryStringMethod('GET,POST'); + $expectedConfiguration = array('parameter' => 123, 'addQueryString' => 1, 'addQueryString.' => array('method' => 'GET,POST'), 'useCacheHash' => 1); + $actualConfiguration = $this->uriBuilder->_call('buildTypolinkConfiguration'); + $this->assertEquals($expectedConfiguration, $actualConfiguration); + } + /** * @test */ diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php index 34b3c348cc0f..4246a6c808fe 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php @@ -63,11 +63,12 @@ class ActionViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBased * @param boolean $absolute If set, the URI of the rendered link is absolute * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE + * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE * @return string Rendered link */ - public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', $linkAccessRestrictedPages = FALSE, array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array()) { + public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', $linkAccessRestrictedPages = FALSE, array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL) { $uriBuilder = $this->controllerContext->getUriBuilder(); - $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setFormat($format)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->uriFor($action, $arguments, $controller, $extensionName, $pluginName); + $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setFormat($format)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->uriFor($action, $arguments, $controller, $extensionName, $pluginName); $this->tag->addAttribute('href', $uri); $this->tag->setContent($this->renderChildren()); $this->tag->forceClosingTag(TRUE); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php index 533fac883bd4..cf9f37cd129a 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php @@ -71,11 +71,24 @@ class PageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedVi * @param boolean $absolute If set, the URI of the rendered link is absolute * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE + * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE * @return string Rendered page URI */ - public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array()) { + public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL) { $uriBuilder = $this->controllerContext->getUriBuilder(); - $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->build(); + $uri = $uriBuilder->reset() + ->setTargetPageUid($pageUid) + ->setTargetPageType($pageType) + ->setNoCache($noCache) + ->setUseCacheHash(!$noCacheHash) + ->setSection($section) + ->setLinkAccessRestrictedPages($linkAccessRestrictedPages) + ->setArguments($additionalParams) + ->setCreateAbsoluteUri($absolute) + ->setAddQueryString($addQueryString) + ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString) + ->setAddQueryStringMethod($addQueryStringMethod) + ->build(); if (strlen($uri)) { $this->tag->addAttribute('href', $uri); $this->tag->setContent($this->renderChildren()); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php index 479a7dc494f5..7ae5dbd4caba 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php @@ -45,11 +45,12 @@ class ActionViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelp * @param boolean $absolute If set, an absolute URI is rendered * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE + * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE * @return string Rendered link */ - public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', $linkAccessRestrictedPages = FALSE, array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array()) { + public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', $linkAccessRestrictedPages = FALSE, array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL) { $uriBuilder = $this->controllerContext->getUriBuilder(); - $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setFormat($format)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->uriFor($action, $arguments, $controller, $extensionName, $pluginName); + $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setFormat($format)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->uriFor($action, $arguments, $controller, $extensionName, $pluginName); return $uri; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php index 67f2cc343ca0..af7ba97dbe55 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php @@ -55,11 +55,12 @@ class PageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper * @param boolean $absolute If set, the URI of the rendered link is absolute * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE + * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE * @return string Rendered page URI */ - public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array()) { + public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL) { $uriBuilder = $this->controllerContext->getUriBuilder(); - $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->build(); + $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->build(); return $uri; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php index 39efdb067a64..84b390929bb3 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php @@ -25,7 +25,7 @@ class PaginateController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetCont /** * @var array */ - protected $configuration = array('itemsPerPage' => 10, 'insertAbove' => FALSE, 'insertBelow' => TRUE, 'maximumNumberOfLinks' => 99); + protected $configuration = array('itemsPerPage' => 10, 'insertAbove' => FALSE, 'insertBelow' => TRUE, 'maximumNumberOfLinks' => 99, 'addQueryStringMethod' => ''); /** * @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/LinkViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/LinkViewHelper.php index 3a2392b539e8..6094174e345a 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/LinkViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/LinkViewHelper.php @@ -54,6 +54,7 @@ class LinkViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedVi $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document'); $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document'); $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); + $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string'); } /** @@ -112,6 +113,9 @@ class LinkViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedVi if ($this->hasArgument('format') && $this->arguments['format'] !== '') { $arguments['format'] = $this->arguments['format']; } - return $uriBuilder->reset()->setArguments(array($argumentPrefix => $arguments))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->build(); + if ($this->hasArgument('addQueryStringMethod') && $this->arguments['addQueryStringMethod'] !== '') { + $arguments['addQueryStringMethod'] = $this->arguments['addQueryStringMethod']; + } + return $uriBuilder->reset()->setArguments(array($argumentPrefix => $arguments))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->build(); } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/UriViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/UriViewHelper.php index bfc7820b914b..dbd53726d41c 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Widget/UriViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Widget/UriViewHelper.php @@ -37,6 +37,16 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Widget; */ class UriViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper { + /** + * Initialize arguments + * + * @return void + * @api + */ + public function initializeArguments() { + $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string'); + } + /** * Render the Uri. * @@ -90,6 +100,9 @@ class UriViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper if ($this->hasArgument('format') && $this->arguments['format'] !== '') { $arguments['format'] = $this->arguments['format']; } - return $uriBuilder->reset()->setArguments(array($argumentPrefix => $arguments))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->build(); + if ($this->hasArgument('addQueryStringMethod') && $this->arguments['addQueryStringMethod'] !== '') { + $arguments['addQueryStringMethod'] = $this->arguments['addQueryStringMethod']; + } + return $uriBuilder->reset()->setArguments(array($argumentPrefix => $arguments))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format'])->build(); } } diff --git a/typo3/sysext/fluid/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html b/typo3/sysext/fluid/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html index ee95a7b8da77..f62e6b8e070a 100644 --- a/typo3/sysext/fluid/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html +++ b/typo3/sysext/fluid/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html @@ -1,11 +1,11 @@ <f:if condition="{configuration.insertAbove}"> - <f:render section="paginator" arguments="{pagination: pagination}" /> + <f:render section="paginator" arguments="{pagination: pagination, configuration: configuration}" /> </f:if> <f:renderChildren arguments="{contentArguments}" /> <f:if condition="{configuration.insertBelow}"> - <f:render section="paginator" arguments="{pagination: pagination}" /> + <f:render section="paginator" arguments="{pagination: pagination, configuration: configuration}" /> </f:if> <f:section name="paginator"> @@ -14,17 +14,17 @@ <li class="previous"> <f:if condition="{pagination.previousPage} > 1"> <f:then> - <f:widget.link arguments="{currentPage: pagination.previousPage}"><f:translate key="widget.pagination.previous" /></f:widget.link> + <f:widget.link arguments="{currentPage: pagination.previousPage}" addQueryStringMethod="{configuration.addQueryStringMethod}"><f:translate key="widget.pagination.previous" /></f:widget.link> </f:then> <f:else> - <f:widget.link><f:translate key="widget.pagination.previous" /></f:widget.link> + <f:widget.link addQueryStringMethod="{configuration.addQueryStringMethod}"><f:translate key="widget.pagination.previous" /></f:widget.link> </f:else> </f:if> </li> </f:if> <f:if condition="{pagination.displayRangeStart} > 1"> <li class="first"> - <f:widget.link>1</f:widget.link> + <f:widget.link addQueryStringMethod="{configuration.addQueryStringMethod}">1</f:widget.link> </li> </f:if> <f:if condition="{pagination.hasLessPages}"> @@ -41,10 +41,10 @@ <li> <f:if condition="{page.number} > 1"> <f:then> - <f:widget.link arguments="{currentPage: page.number}">{page.number}</f:widget.link> + <f:widget.link arguments="{currentPage: page.number}" addQueryStringMethod="{configuration.addQueryStringMethod}">{page.number}</f:widget.link> </f:then> <f:else> - <f:widget.link>{page.number}</f:widget.link> + <f:widget.link addQueryStringMethod="{configuration.addQueryStringMethod}">{page.number}</f:widget.link> </f:else> </f:if> </li> @@ -56,12 +56,12 @@ </f:if> <f:if condition="{pagination.displayRangeEnd} < {pagination.numberOfPages}"> <li class="last"> - <f:widget.link arguments="{currentPage: pagination.numberOfPages}">{pagination.numberOfPages}</f:widget.link> + <f:widget.link arguments="{currentPage: pagination.numberOfPages}" addQueryStringMethod="{configuration.addQueryStringMethod}">{pagination.numberOfPages}</f:widget.link> </li> </f:if> <f:if condition="{pagination.nextPage}"> <li class="next"> - <f:widget.link arguments="{currentPage: pagination.nextPage}"><f:translate key="widget.pagination.next" /></f:widget.link> + <f:widget.link arguments="{currentPage: pagination.nextPage}" addQueryStringMethod="{configuration.addQueryStringMethod}"><f:translate key="widget.pagination.next" /></f:widget.link> </li> </f:if> </ul> diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ViewHelperBaseTestcase.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ViewHelperBaseTestcase.php index c54553da237d..0c202647fbcc 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ViewHelperBaseTestcase.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ViewHelperBaseTestcase.php @@ -80,6 +80,7 @@ abstract class ViewHelperBaseTestcase extends \TYPO3\CMS\Extbase\Tests\Unit\Base $this->uriBuilder->expects($this->any())->method('setTargetPageType')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setNoCache')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setUseCacheHash')->will($this->returnValue($this->uriBuilder)); + $this->uriBuilder->expects($this->any())->method('setAddQueryStringMethod')->will($this->returnValue($this->uriBuilder)); $this->request = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request'); $this->controllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE); $this->controllerContext->expects($this->any())->method('getUriBuilder')->will($this->returnValue($this->uriBuilder)); -- GitLab