[FEATURE] uriBuilder should honor POST arguments for addQueryString 32/22432/5
authorStanislas Rolland <typo3@sjbr.ca>
Fri, 19 Jul 2013 19:31:09 +0000 (15:31 -0400)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 12 Oct 2013 15:03:42 +0000 (17:03 +0200)
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
typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php
typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php
typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php
typo3/sysext/fluid/Classes/ViewHelpers/Widget/LinkViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Widget/UriViewHelper.php
typo3/sysext/fluid/Resources/Private/Templates/ViewHelpers/Widget/Paginate/Index.html
typo3/sysext/fluid/Tests/Unit/ViewHelpers/ViewHelperBaseTestcase.php

index 56a3ab2..89cb372 100644 (file)
@@ -77,6 +77,11 @@ class UriBuilder {
        protected $addQueryString = FALSE;
 
        /**
+        * @var string
+        */
+       protected $addQueryStringMethod = NULL;
+
+       /**
         * @var array
         */
        protected $argumentsToBeExcludedFromQueryString = array();
@@ -271,6 +276,28 @@ class UriBuilder {
        }
 
        /**
+        * 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;
index 6bff949..73729fe 100644 (file)
@@ -43,6 +43,11 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $getBackup;
 
        /**
+        * @var array
+        */
+       protected $postBackup;
+
+       /**
         * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
         */
        protected $mockConfigurationManager;
@@ -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);
@@ -207,10 +232,13 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                                        '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(
@@ -219,10 +247,13 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                                        '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(
@@ -233,10 +264,13 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                                        '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(
@@ -249,10 +283,13 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                                        '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());
@@ -460,6 +500,29 @@ class UriBuilderTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @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
+        */
        public function buildTypolinkConfigurationConvertsDomainObjects() {
                $mockDomainObject1 = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity', array('dummy'));
                $mockDomainObject1->_set('uid', '123');
index 34b3c34..4246a6c 100644 (file)
@@ -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);
index 533fac8..cf9f37c 100644 (file)
@@ -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());
index 479a7dc..7ae5dbd 100644 (file)
@@ -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;
        }
 }
index 67f2cc3..af7ba97 100644 (file)
@@ -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;
        }
 }
index 39efdb0..84b3909 100644 (file)
@@ -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
index 3a2392b..6094174 100644 (file)
@@ -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();
        }
 }
index bfc7820..dbd5372 100644 (file)
@@ -38,6 +38,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.
         *
         * @param string $action Target action
@@ -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();
        }
 }
index ee95a7b..f62e6b8 100644 (file)
@@ -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">
                        <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}">
                                        <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>
                </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>
index c54553d..0c20264 100644 (file)
@@ -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));