Skip to content

Commit

Permalink
[FEATURE] Add absolute option to typolink VHs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bmack committed Mar 3, 2018
1 parent 03516bc commit 61a6338
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
@@ -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
Expand Up @@ -77,6 +77,7 @@ public function initializeArguments()
$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);
}

/**
Expand All @@ -101,6 +102,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$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);
Expand Down Expand Up @@ -130,7 +132,8 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
'addQueryString.' => [
'method' => $addQueryStringMethod,
'exclude' => $addQueryStringExclude
]
],
'forceAbsoluteUrl' => $absolute
]
]
);
Expand Down
Expand Up @@ -60,6 +60,7 @@ public function initializeArguments()
$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);
}

/**
Expand All @@ -77,6 +78,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$addQueryString = $arguments['addQueryString'];
$addQueryStringMethod = $arguments['addQueryStringMethod'];
$addQueryStringExclude = $arguments['addQueryStringExclude'];
$absolute = $arguments['absolute'];

$content = '';
if ($parameter) {
Expand All @@ -89,7 +91,8 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
'addQueryString.' => [
'method' => $addQueryStringMethod,
'exclude' => $addQueryStringExclude
]
],
'forceAbsoluteUrl' => $absolute
]
);
}
Expand Down
Expand Up @@ -86,6 +86,7 @@ public function renderCallsStdWrapWithrightParameters()
'addQueryString' => $addQueryString,
'addQueryStringMethod' => $addQueryStringMethod,
'addQueryStringExclude' => $addQueryStringExclude,
'absolute' => false
]);
$contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
$contentObjectRendererMock->expects($this->once())
Expand All @@ -102,6 +103,7 @@ public function renderCallsStdWrapWithrightParameters()
'method' => $addQueryStringMethod,
'exclude' => $addQueryStringExclude,
],
'forceAbsoluteUrl' => false,
],
]
)
Expand Down

0 comments on commit 61a6338

Please sign in to comment.