Commit dc749a15 authored by Mathias Brodala's avatar Mathias Brodala Committed by Benni Mack
Browse files

[BUGFIX] Do not link to untranslated records

This only fixes the issue for dedicated record links. Page links with
added query arguments can still lead to broken links.

Resolves: #87260
Releases: main, 11.5
Change-Id: Ib13aa1925de6463688e2b50612ce7b2820733ce7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72788


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 1d5d5743
......@@ -47,11 +47,26 @@ class DatabaseRecordLinkBuilder extends AbstractTypolinkBuilder
}
$typoScriptConfiguration = $configuration[$configurationKey]['typolink.'];
$linkHandlerConfiguration = $linkHandlerConfiguration[$configurationKey]['configuration.'];
$databaseTable = $linkHandlerConfiguration['table'];
if ($configuration[$configurationKey]['forceLink'] ?? false) {
$record = $tsfe->sys_page->getRawRecord($linkHandlerConfiguration['table'], $linkDetails['uid']);
$record = $tsfe->sys_page->getRawRecord($databaseTable, $linkDetails['uid']);
} else {
$record = $tsfe->sys_page->checkRecord($linkHandlerConfiguration['table'], $linkDetails['uid']);
$record = $tsfe->sys_page->checkRecord($databaseTable, $linkDetails['uid']);
$languageAspect = $tsfe->getContext()->getAspect('language');
if ($languageAspect->doOverlays()) {
$overlay = $tsfe->sys_page->getRecordOverlay(
$databaseTable,
$record,
$languageAspect->getContentId(),
$languageAspect->getLegacyOverlayType()
);
if (empty($overlay['_LOCALIZED_UID'])) {
$record = 0;
}
}
}
if ($record === 0) {
throw new UnableToLinkException(
......@@ -81,7 +96,7 @@ class DatabaseRecordLinkBuilder extends AbstractTypolinkBuilder
// Build the full link to the record
$request = $this->contentObjectRenderer->getRequest();
$localContentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$localContentObjectRenderer->start($record, $linkHandlerConfiguration['table'], $request);
$localContentObjectRenderer->start($record, $databaseTable, $request);
$localContentObjectRenderer->parameters = $this->contentObjectRenderer->parameters;
$link = $localContentObjectRenderer->typoLink($linkText, $typoScriptConfiguration);
......
......@@ -40,12 +40,19 @@ entities:
- self: {id: 1102, title: 'FR-CA: Bienvenue', language: 2, slug: '/bienvenue', subtitle: 'salut-et-bienvenue'}
entities:
content:
- self: {title: 'EN: Content Element #1'}
- self: {title: 'EN: Content Element #2'}
- self: {id: 300, title: 'EN: Content Element #1'}
- self: {id: 310, title: 'EN: Content Element #2'}
- self: {id: 1200, title: 'EN: Features', slug: '/features'}
languageVariants:
- self: {id: 1201, title: 'FR: Features', slug: '/features-fr', language: 1}
- self: {id: 1202, title: 'FR-CA: Features', slug: '/features-ca', language: 2}
entities:
content:
- self: {id: 400, title: 'EN: Content Element #1'}
languageVariants:
- self: {id: 401, title: 'FR: Content Element #1', language: 1 }
- self: {id: 402, title: 'FR-CA: EN: Content Element #1', language: 2, slug: '/bienvenue' }
- self: {title: 'EN: Content Element #2'}
- self: {id: 1300, title: 'Go to TYPO3.org', type: *pageLink, slug: '/external', url: 'typo3.org' }
- self: {id: 9911, title: '<good>', slug: '/test/good'}
- self: {id: 9912, title: '<good a="a/" b="thing(1)">', slug: '/test/good-a-b-spaced'}
......
......@@ -160,8 +160,16 @@ class TypoLinkGeneratorTest extends AbstractTestCase
'<a href="http://typo3.org">Go to TYPO3.org</a>',
],
[
't3://record?identifier=content&uid=10001&other=other#fragment',
'<a href="/features#c10001">EN: Features</a>',
't3://record?identifier=content&uid=400&other=other#fragment',
'<a href="/features#c400">EN: Features</a>',
],
'Non-existent record' => [
't3://record?identifier=content&uid=400000',
'',
],
'Translated record on default language page' => [
't3://record?identifier=content&uid=402',
'<a href="/features#c402">EN: Features</a>',
],
[
't3://url?url=https://typo3.org%3f%26param-a=a%26param-b=b&other=other#other',
......@@ -517,14 +525,15 @@ class TypoLinkGeneratorTest extends AbstractTestCase
private function invokeTypoLink(string $parameter, AbstractInstruction ...$instructions): InternalResponse
{
$sourcePageId = 1100;
$targetPageId = 1200;
$request = (new InternalRequest('https://acme.us/'))
->withPageId($sourcePageId)
->withInstructions(
[
$this->createRecordLinksInstruction([
'parameter' => $targetPageId,
'parameter.' => [
'data' => 'field:pid',
],
'section.' => [
'data' => 'field:uid',
'wrap' => 'c|',
......@@ -569,7 +578,6 @@ class TypoLinkGeneratorTest extends AbstractTestCase
'config.' => [
'recordLinks.' => [
'content.' => [
'forceLink' => 1,
'typolink.' => $typoLink,
],
],
......
......@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Typolink;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -168,12 +169,13 @@ class DatabaseRecordLinkBuilderTest extends UnitTestCase
// Arrange
$tsfe = $this->prophesize(TypoScriptFrontendController::class);
$context = new Context();
$templateService = $this->prophesize(TemplateService::class);
$pageRepository = $this->prophesize(PageRepository::class);
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->getRequest()->willReturn($this->prophesize(ServerRequestInterface::class)->reveal());
$GLOBALS['TSFE'] = $tsfe->reveal();
$tsfe->getContext()->willReturn($context);
$tsfe->tmpl = $templateService->reveal();
$tsfe->tmpl->setup = $typoScriptConfig;
$tsfe->sys_page = $pageRepository->reveal();
......@@ -191,7 +193,7 @@ class DatabaseRecordLinkBuilderTest extends UnitTestCase
$tsfe->getPagesTSconfig()->willReturn($pageTsConfig);
// Act
$databaseRecordLinkBuilder = new DatabaseRecordLinkBuilder($cObj->reveal());
$databaseRecordLinkBuilder = new DatabaseRecordLinkBuilder($cObj->reveal(), $tsfe->reveal());
try {
$databaseRecordLinkBuilder->build($extractedLinkDetails, $linkText, $target, $confFromDb);
} catch (UnableToLinkException $exception) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment