Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Classes/Controller/PublicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -101,7 +103,7 @@ public function downloadBibtexAction(Filter $filter): ResponseInterface
$this->view->assignMultiple(
[
'filter' => $filter,
'publications' => $publications
'publications' => $this->renderPublicationsLinks($publications)
]
);

Expand Down Expand Up @@ -130,7 +132,7 @@ public function downloadXmlAction(Filter $filter): ResponseInterface
$this->view->assignMultiple(
[
'filter' => $filter,
'publications' => $publications
'publications' => $this->renderPublicationsLinks($publications)
]
);

Expand Down Expand Up @@ -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;
Expand Down