2 declare(strict_types
=1);
3 namespace TYPO3\CMS\Frontend\Typolink
;
6 * This file is part of the TYPO3 CMS project.
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
19 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
;
22 * Builds a TypoLink to a database record
24 class DatabaseRecordLinkBuilder
extends AbstractTypolinkBuilder
29 public function build(array &$linkDetails, string $linkText, string $target, array $conf): array
31 $tsfe = $this->getTypoScriptFrontendController();
32 $pageTsConfig = $tsfe->getPagesTSconfig();
33 $configurationKey = $linkDetails['identifier'] . '.';
34 $configuration = $tsfe->tmpl
->setup
['config.']['recordLinks.'];
35 $linkHandlerConfiguration = $pageTsConfig['TCEMAIN.']['linkHandler.'];
37 if (!isset($configuration[$configurationKey]) ||
!isset($linkHandlerConfiguration[$configurationKey])) {
38 throw new UnableToLinkException(
39 'Configuration how to link "' . $linkDetails['typoLinkParameter'] . '" was not found, so "' . $linkText . '" was not linked.',
45 $typoScriptConfiguration = $configuration[$configurationKey]['typolink.'];
46 $linkHandlerConfiguration = $linkHandlerConfiguration[$configurationKey]['configuration.'];
48 if ($configuration[$configurationKey]['forceLink']) {
49 $record = $tsfe->sys_page
->getRawRecord($linkHandlerConfiguration['table'], $linkDetails['uid']);
51 $record = $tsfe->sys_page
->checkRecord($linkHandlerConfiguration['table'], $linkDetails['uid']);
54 throw new UnableToLinkException(
55 'Record not found for "' . $linkDetails['typoLinkParameter'] . '" was not found, so "' . $linkText . '" was not linked.',
62 // Build the full link to the record
63 $localContentObjectRenderer = GeneralUtility
::makeInstance(ContentObjectRenderer
::class);
64 $localContentObjectRenderer->start($record, $linkHandlerConfiguration['table']);
65 $localContentObjectRenderer->parameters
= $this->contentObjectRenderer
->parameters
;
66 $link = $localContentObjectRenderer->typoLink($linkText, $typoScriptConfiguration);
68 $this->contentObjectRenderer
->lastTypoLinkLD
= $localContentObjectRenderer->lastTypoLinkLD
;
69 $this->contentObjectRenderer
->lastTypoLinkUrl
= $localContentObjectRenderer->lastTypoLinkUrl
;
70 $this->contentObjectRenderer
->lastTypoLinkTarget
= $localContentObjectRenderer->lastTypoLinkTarget
;
72 // nasty workaround so typolink stops putting a link together, there is a link already built
73 throw new UnableToLinkException(
74 '', 1491130170, null, $link