From 41fc71db8013578c331e9df51c70d7d3eada0d80 Mon Sep 17 00:00:00 2001 From: Eric Chavaillaz <eric@hemmer.ch> Date: Fri, 8 Nov 2019 11:33:11 +0100 Subject: [PATCH] [TASK] Do not add target attribute if lightbox is enabled If config.fileTarget is set, per example to "_blank", the target is set as fallbak on file link. The target is also added on click enlarge link but it is not wanted if lightbox is enabled. This patch ensure that the target attribute is not printed when lightbox is enabled. Resolves: #89613 Releases: master, 9.5 Change-Id: Ib40359939a7d8689f43b3418b7b5865794046f1d Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62248 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com> Tested-by: Henning Liebe <h.liebe@neusta.de> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com> Reviewed-by: Henning Liebe <h.liebe@neusta.de> Reviewed-by: Benni Mack <benni@typo3.org> --- .../ContentObject/ContentObjectRenderer.php | 1 + .../Classes/Typolink/AbstractTypolinkBuilder.php | 2 +- .../ContentObject/ContentObjectRendererTest.php | 15 +++++++++++++++ .../Unit/Typolink/AbstractTypolinkBuilderTest.php | 10 +++++----- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 938dafd72b88..4333cb688f3e 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -1374,6 +1374,7 @@ class ContentObjectRenderer implements LoggerAwareInterface $a2 = '</a>'; $this->getTypoScriptFrontendController()->setJS('openPic'); } else { + $conf['linkParams.']['directImageLink'] = (bool)$conf['directImageLink']; $conf['linkParams.']['parameter'] = $url; $string = $this->typoLink($string, $conf['linkParams.']); } diff --git a/typo3/sysext/frontend/Classes/Typolink/AbstractTypolinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/AbstractTypolinkBuilder.php index fdd147a33e08..6a92933a4ff4 100644 --- a/typo3/sysext/frontend/Classes/Typolink/AbstractTypolinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/AbstractTypolinkBuilder.php @@ -183,7 +183,7 @@ abstract class AbstractTypolinkBuilder $target = ''; if (isset($conf[$name])) { $target = $conf[$name]; - } elseif ($targetAttributeAllowed) { + } elseif ($targetAttributeAllowed && !$conf['directImageLink']) { $target = $fallbackTarget; } if (isset($conf[$name . '.']) && $conf[$name . '.']) { diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 90730aa3e539..b8ad463740a4 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -2658,6 +2658,7 @@ class ContentObjectRendererTest extends UnitTestCase 'constants' => '1', ], 'typolink.' => [ + 'directImageLink' => false, 'extTarget.' => [ 'override' => '', ], @@ -2739,6 +2740,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to url' => [ 'TYPO3', [ + 'directImageLink' => false, 'parameter' => 'http://typo3.org', ], '<a href="http://typo3.org">TYPO3</a>', @@ -2746,6 +2748,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to url without schema' => [ 'TYPO3', [ + 'directImageLink' => false, 'parameter' => 'typo3.org', ], '<a href="http://typo3.org">TYPO3</a>', @@ -2753,6 +2756,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to url without link text' => [ '', [ + 'directImageLink' => false, 'parameter' => 'http://typo3.org', ], '<a href="http://typo3.org">http://typo3.org</a>', @@ -2794,6 +2798,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to url with script tag' => [ '', [ + 'directImageLink' => false, 'parameter' => 'http://typo3.org<script>alert(123)</script>', ], '<a href="http://typo3.org<script>alert(123)</script>">http://typo3.org<script>alert(123)</script></a>', @@ -3006,6 +3011,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to file' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => 'fileadmin/foo.bar', ], '<a href="fileadmin/foo.bar">My file</a>', @@ -3013,6 +3019,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to file without link text' => [ '', [ + 'directImageLink' => false, 'parameter' => 'fileadmin/foo.bar', ], '<a href="fileadmin/foo.bar">fileadmin/foo.bar</a>', @@ -3087,6 +3094,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to file with script tag in name' => [ '', [ + 'directImageLink' => false, 'parameter' => 'fileadmin/<script>alert(123)</script>', ], '<a href="fileadmin/<script>alert(123)</script>">fileadmin/<script>alert(123)</script></a>', @@ -3139,6 +3147,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to file' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => 'fileadmin/foo.bar', ], '/', @@ -3147,6 +3156,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to file with longer absRefPrefix' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => 'fileadmin/foo.bar', ], '/sub/', @@ -3155,6 +3165,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to absolute file' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => '/images/foo.bar', ], '/', @@ -3163,6 +3174,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to absolute file with longer absRefPrefix' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => '/images/foo.bar', ], '/sub/', @@ -3171,6 +3183,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to absolute file with identical longer absRefPrefix' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => '/sub/fileadmin/foo.bar', ], '/sub/', @@ -3179,6 +3192,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to file with empty absRefPrefix' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => 'fileadmin/foo.bar', ], '', @@ -3187,6 +3201,7 @@ class ContentObjectRendererTest extends UnitTestCase 'Link to absolute file with empty absRefPrefix' => [ 'My file', [ + 'directImageLink' => false, 'parameter' => '/fileadmin/foo.bar', ], '', diff --git a/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php b/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php index d4d095cb0964..fc7d5891db88 100644 --- a/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php @@ -252,7 +252,7 @@ class AbstractTypolinkBuilderTest extends UnitTestCase 'Else from fallback, if not $respectFrameSetOption ...' => [ $fallback, - [], + ['directImageLink' => false], $targetName, false, // $respectFrameSetOption false $fallback, @@ -261,7 +261,7 @@ class AbstractTypolinkBuilderTest extends UnitTestCase ' ... or no doctype ... ' => [ $fallback, - [], + ['directImageLink' => false], $targetName, true, $fallback, @@ -270,7 +270,7 @@ class AbstractTypolinkBuilderTest extends UnitTestCase ' ... or doctype xhtml_trans... ' => [ $fallback, - [], + ['directImageLink' => false], $targetName, true, $fallback, @@ -279,7 +279,7 @@ class AbstractTypolinkBuilderTest extends UnitTestCase ' ... or doctype xhtml_basic... ' => [ $fallback, - [], + ['directImageLink' => false], $targetName, true, $fallback, @@ -288,7 +288,7 @@ class AbstractTypolinkBuilderTest extends UnitTestCase ' ... or doctype html5... ' => [ $fallback, - [], + ['directImageLink' => false], $targetName, true, $fallback, -- GitLab