[FEATURE] Add absolute option to typolink VHs 90/55990/3
authorBenni Mack <benni@typo3.org>
Fri, 2 Mar 2018 15:36:44 +0000 (16:36 +0100)
committerBenni Mack <benni@typo3.org>
Sat, 3 Mar 2018 20:48:17 +0000 (21:48 +0100)
In order to generate absolute URLs through the
Typolink ViewHelpers of TYPO3 Fluid, a new
fluid parameter "absolute" is added to the following
ViewHelpers.

* <f:link.typolink>
* <f:uri.typolink>

As typolink() is allowing this option, the generation
of absolute URLs behaves the same way as typolink()
itself does it.

Use it like this:

The ViewHelper code:
- <f:link.typolink parameter="23">Link To My Page</f:link.typolink>
generates:
- <a href="index.php?id=23">Link to My Page</a>

The ViewHelper code:
- <f:link.typolink parameter="23" absolute="true">Link To My Page</f:link.typolink>
generates:
- <a href="https://www.mydomain.com/index.php?id=23">Link to My Page</a>

The ViewHelper code:
- <f:uri.typolink parameter="23" />
generates:
- "index.php?id=23"

The ViewHelper code:
- <f:uri.typolink parameter="23" absolute="true" />
generates:
- "https://www.mydomain.com/index.php?id=23"

Resolves: #84120
Releases: master
Change-Id: I6b6df0ebc8a7c257ab854959e5425debd0cadd5e
Reviewed-on: https://review.typo3.org/55990
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/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/master/Feature-84120-AbsoluteURLsForTypolinkViewHelpers.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-84120-AbsoluteURLsForTypolinkViewHelpers.rst
new file mode 100644 (file)
index 0000000..3342380
--- /dev/null
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Feature: #84120 - Absolute URLs for typolink ViewHelpers
+========================================================
+
+See :issue:`84120`
+
+Description
+===========
+
+A new parameter "absolute" is 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 db306a0..97b4d0d 100644 (file)
@@ -77,6 +77,7 @@ class TypolinkViewHelper extends AbstractViewHelper
         $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);
     }
 
     /**
@@ -101,6 +102,7 @@ class TypolinkViewHelper extends AbstractViewHelper
         $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);
@@ -130,7 +132,8 @@ class TypolinkViewHelper extends AbstractViewHelper
                         'addQueryString.' => [
                             'method' => $addQueryStringMethod,
                             'exclude' => $addQueryStringExclude
-                        ]
+                        ],
+                        'forceAbsoluteUrl' => $absolute
                     ]
                 ]
             );
index 4607091..b339288 100644 (file)
@@ -60,6 +60,7 @@ class TypolinkViewHelper extends AbstractViewHelper
         $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);
     }
 
     /**
@@ -77,6 +78,7 @@ class TypolinkViewHelper extends AbstractViewHelper
         $addQueryString = $arguments['addQueryString'];
         $addQueryStringMethod = $arguments['addQueryStringMethod'];
         $addQueryStringExclude = $arguments['addQueryStringExclude'];
+        $absolute = $arguments['absolute'];
 
         $content = '';
         if ($parameter) {
@@ -89,7 +91,8 @@ class TypolinkViewHelper extends AbstractViewHelper
                     'addQueryString.' => [
                         'method' => $addQueryStringMethod,
                         'exclude' => $addQueryStringExclude
-                    ]
+                    ],
+                    'forceAbsoluteUrl' => $absolute
                 ]
             );
         }
index dc8fdb6..2b24230 100644 (file)
@@ -86,6 +86,7 @@ class TypolinkViewHelperTest extends ViewHelperBaseTestcase
             'addQueryString' => $addQueryString,
             'addQueryStringMethod' => $addQueryStringMethod,
             'addQueryStringExclude' => $addQueryStringExclude,
+            'absolute' => false
         ]);
         $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
         $contentObjectRendererMock->expects($this->once())
@@ -102,6 +103,7 @@ class TypolinkViewHelperTest extends ViewHelperBaseTestcase
                             'method' => $addQueryStringMethod,
                             'exclude' => $addQueryStringExclude,
                         ],
+                        'forceAbsoluteUrl' => false,
                     ],
                 ]
             )