From 699884e4379616e6521dbd60688d98cfc3a58b42 Mon Sep 17 00:00:00 2001 From: Yann Weyer Date: Tue, 10 Nov 2026 10:51:13 +0100 Subject: [PATCH] [BUGFIX] Render Typolinks in publications exports --- Classes/Controller/PublicationController.php | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Classes/Controller/PublicationController.php b/Classes/Controller/PublicationController.php index 3b30fc2..64d782c 100644 --- a/Classes/Controller/PublicationController.php +++ b/Classes/Controller/PublicationController.php @@ -5,6 +5,7 @@ namespace In2code\Publications\Controller; use In2code\Publications\Domain\Model\Dto\Filter; +use In2code\Publications\Domain\Model\Publication; use In2code\Publications\Domain\Repository\PublicationRepository; use In2code\Publications\Domain\Service\PublicationService; use In2code\Publications\Pagination\NumberedPagination; @@ -15,6 +16,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; +use TYPO3\CMS\Extbase\Reflection\ObjectAccess; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; /** @@ -101,7 +103,7 @@ public function downloadBibtexAction(Filter $filter): ResponseInterface $this->view->assignMultiple( [ 'filter' => $filter, - 'publications' => $publications + 'publications' => $this->renderPublicationsLinks($publications) ] ); @@ -130,7 +132,7 @@ public function downloadXmlAction(Filter $filter): ResponseInterface $this->view->assignMultiple( [ 'filter' => $filter, - 'publications' => $publications + 'publications' => $this->renderPublicationsLinks($publications) ] ); @@ -183,6 +185,41 @@ protected function setFilterArguments(): void $this->request = $this->request->withArgument('currentContentObject', $this->getContentObject()); } + /** + * Render Typolinks in publications attributes + * + * @param Publication[] $publications + * @return Publication[] + */ + protected function renderPublicationsLinks(array $publications): array + { + // Get the name of all columns that might store typolinks in the publications model + $linkCols = array_keys(array_filter( + $GLOBALS['TCA']['tx_publications_domain_model_publication']['columns'], + static fn ($value) => 'typolink' === ($value['config']['softref'] ?? '') + )); + + foreach ($publications as &$publication) { + foreach ($linkCols as $propertyName) { + $value = ObjectAccess::getProperty($publication, $propertyName); + + // Only consider typo3 internal links (t3://…) + if (is_string($value) && 't3' === parse_url($value, PHP_URL_SCHEME)) { + // Try to generate the corresponding URL + $url = $this->getContentObject()->createUrl([ + 'parameter' => $value, + 'forceAbsoluteUrl' => true, + ]); + if ($url) { + ObjectAccess::setProperty($publication, $propertyName, $url); + } + } + } + } + + return $publications; + } + protected function getContentObject(): ?ContentObjectRenderer { return $this->request->getAttribute('currentContentObject') ?? null;