[BUGFIX] Backport essential features into TypoLinkViewHelper classes 33/58933/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 22 Nov 2018 14:48:18 +0000 (15:48 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Mon, 10 Dec 2018 18:33:38 +0000 (19:33 +0100)
This patch backports essential support for `forceAbsoluteUrl` and
`addQueryString` to the TypoLinkViewHelper classes.

Resolves: #86977
Related: #84120
Related: #81358
Releases: 8.7
Change-Id: Iab4d1c49a2be46108d6e7578ba418eb89d24b532
Reviewed-on: https://review.typo3.org/58933
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Jonas Eberle <flightvision@googlemail.com>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Documentation/Changelog/8.7.x/Feature-84120-AbsoluteURLsForTypolinkViewHelpers.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/TypolinkViewHelperTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/8.7.x/Feature-84120-AbsoluteURLsForTypolinkViewHelpers.rst b/typo3/sysext/core/Documentation/Changelog/8.7.x/Feature-84120-AbsoluteURLsForTypolinkViewHelpers.rst
new file mode 100644 (file)
index 0000000..30af571
--- /dev/null
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Feature: #84120 - Absolute URLs for typolink ViewHelpers
+========================================================
+
+See :issue:`84120`
+
+Description
+===========
+
+The new parameter `absolute` has been added to the Fluid ViewHelpers `<f:uri.typolink>` and `<f:link.typolink>`,
+allowing to generate absolute links, like other ViewHelpers used for linking handle it already.
+
+
+Impact
+======
+
+It is now possible to add the `absolute` parameter to the ViewHelpers above.
+
+.. code-block:: html
+
+    <f:link.typolink parameter="23" absolute="true">Link To My Page</f:link.typolink>
+    <f:uri.typolink parameter="23" absolute="true" />
+
+generates
+
+.. code-block:: html
+
+    <a href="https://www.mydomain.com/index.php?id=23">Link to My Page</a>
+    https://www.mydomain.com/index.php?id=23
+
+.. index:: Fluid, ext:fluid
\ No newline at end of file
index ac02693..48995db 100644 (file)
@@ -74,6 +74,10 @@ class TypolinkViewHelper extends AbstractViewHelper
         $this->registerArgument('additionalParams', 'string', '', false, '');
         $this->registerArgument('additionalAttributes', 'array', '', false, []);
         $this->registerArgument('useCacheHash', 'bool', '', false, false);
+        $this->registerArgument('addQueryString', 'bool', '', false, false);
+        $this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
+        $this->registerArgument('addQueryStringExclude', 'string', '', false, '');
+        $this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
     }
 
     /**
@@ -95,6 +99,10 @@ class TypolinkViewHelper extends AbstractViewHelper
         $additionalParams = $arguments['additionalParams'];
         $additionalAttributes = $arguments['additionalAttributes'];
         $useCacheHash = $arguments['useCacheHash'];
+        $addQueryString = $arguments['addQueryString'];
+        $addQueryStringMethod = $arguments['addQueryStringMethod'];
+        $addQueryStringExclude = $arguments['addQueryStringExclude'];
+        $absolute = $arguments['absolute'];
 
         // Merge the $parameter with other arguments
         $typolinkParameter = self::createTypolinkParameterArrayFromArguments($parameter, $target, $class, $title, $additionalParams);
@@ -120,6 +128,12 @@ class TypolinkViewHelper extends AbstractViewHelper
                         'parameter' => $typolinkParameter,
                         'ATagParams' => $aTagParams,
                         'useCacheHash' => $useCacheHash,
+                        'addQueryString' => $addQueryString,
+                        'addQueryString.' => [
+                            'method' => $addQueryStringMethod,
+                            'exclude' => $addQueryStringExclude
+                        ],
+                        'forceAbsoluteUrl' => $absolute
                     ]
                 ]
             );
index 43dfe35..8b421cf 100644 (file)
@@ -57,6 +57,10 @@ class TypolinkViewHelper extends AbstractViewHelper
         $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
         $this->registerArgument('additionalParams', 'string', 'stdWrap.typolink additionalParams', false, '');
         $this->registerArgument('useCacheHash', 'bool', '', false, false);
+        $this->registerArgument('addQueryString', 'bool', '', false, false);
+        $this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
+        $this->registerArgument('addQueryStringExclude', 'string', '', false, '');
+        $this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
     }
 
     /**
@@ -71,6 +75,10 @@ class TypolinkViewHelper extends AbstractViewHelper
         $parameter = $arguments['parameter'];
         $additionalParams = $arguments['additionalParams'];
         $useCacheHash = $arguments['useCacheHash'];
+        $addQueryString = $arguments['addQueryString'];
+        $addQueryStringMethod = $arguments['addQueryStringMethod'];
+        $addQueryStringExclude = $arguments['addQueryStringExclude'];
+        $absolute = $arguments['absolute'];
 
         $content = '';
         if ($parameter) {
@@ -79,6 +87,12 @@ class TypolinkViewHelper extends AbstractViewHelper
                 [
                     'parameter' => self::createTypolinkParameterFromArguments($parameter, $additionalParams),
                     'useCacheHash' => $useCacheHash,
+                    'addQueryString' => $addQueryString,
+                    'addQueryString.' => [
+                        'method' => $addQueryStringMethod,
+                        'exclude' => $addQueryStringExclude
+                    ],
+                    'forceAbsoluteUrl' => $absolute
                 ]
             );
         }
index 5de4440..9d21663 100644 (file)
@@ -44,6 +44,52 @@ class TypolinkViewHelperTest extends ViewHelperBaseTestcase
     /**
      * @test
      */
+    public function renderCallsStdWrapWithrightParameters()
+    {
+        $addQueryString = true;
+        $addQueryStringMethod = 'GET,POST';
+        $addQueryStringExclude = 'cHash';
+
+        $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
+        $this->subject->setArguments([
+            'parameter' => '42',
+            'target' => '',
+            'class' => '',
+            'title' => '',
+            'additionalParams' => '',
+            'additionalAttributes' => [],
+            'addQueryString' => $addQueryString,
+            'addQueryStringMethod' => $addQueryStringMethod,
+            'addQueryStringExclude' => $addQueryStringExclude,
+            'absolute' => false
+        ]);
+        $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
+        $contentObjectRendererMock->expects($this->once())
+            ->method('stdWrap')
+            ->with(
+                'innerContent',
+                [
+                    'typolink.' => [
+                        'parameter' => '42',
+                        'ATagParams' => '',
+                        'useCacheHash' => false,
+                        'addQueryString' => $addQueryString,
+                        'addQueryString.' => [
+                            'method' => $addQueryStringMethod,
+                            'exclude' => $addQueryStringExclude,
+                        ],
+                        'forceAbsoluteUrl' => false,
+                    ],
+                ]
+            )
+            ->will($this->returnValue('foo'));
+        GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
+        $this->assertEquals('foo', $this->subject->render());
+    }
+
+    /**
+     * @test
+     */
     public function renderReturnsResultOfContentObjectRenderer()
     {
         $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));