Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 11 additions & 23 deletions Classes/XClass/Preview/PreviewUriBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,45 @@
/**
* @codeCoverageIgnore
*/
class PreviewUriBuilder extends \TYPO3\CMS\Workspaces\Preview\PreviewUriBuilder
readonly class PreviewUriBuilder extends \TYPO3\CMS\Workspaces\Preview\PreviewUriBuilder
{
private ?HeadlessModeInterface $headlessMode = null;
private ?SiteFinder $siteFinder = null;
private ?HeadlessFrontendUrlInterface $urlUtility = null;

private function getHeadlessMode(): HeadlessModeInterface
{
return $this->headlessMode ??= GeneralUtility::makeInstance(HeadlessModeInterface::class);
return GeneralUtility::makeInstance(HeadlessModeInterface::class);
}

private function getSiteFinder(): SiteFinder
{
return $this->siteFinder ??= GeneralUtility::makeInstance(SiteFinder::class);
return GeneralUtility::makeInstance(SiteFinder::class);
}

private function getUrlUtility(): HeadlessFrontendUrlInterface
{
return $this->urlUtility ??= GeneralUtility::makeInstance(HeadlessFrontendUrlInterface::class);
return GeneralUtility::makeInstance(HeadlessFrontendUrlInterface::class);
}

/**
* Generates a workspace preview link.
*
* @param int $uid The ID of the record to be linked
* @param int $languageId the language to link to
* @return string the full domain including the protocol http:// or https://, but without the trailing '/'
*/
public function buildUriForPage(int $uid, int $languageId = 0): string
{
$previewKeyword = $this->compilePreviewKeyword(
$this->previewLinkLifetime * 3600,
$this->workspaceService->getCurrentWorkspace()
);

$previewKeyword = $this->compilePreviewKeyword();
try {
$site = $this->getSiteFinder()->getSiteByPageId($uid);
try {
$language = $site->getLanguageById($languageId);
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException) {
$language = $site->getDefaultLanguage();
}

$uri = $site->getRouter()->generateUri($uid, ['ADMCMD_prev' => $previewKeyword, '_language' => $language], '');

$headlessMode = $this->getHeadlessMode()->withRequest($GLOBALS['TYPO3_REQUEST']);
$request = $headlessMode->overrideBackendRequestBySite($site, $language);

return $this->getUrlUtility()
->withRequest($request)
->getFrontendUrlForPage((string)$site->getRouter()->generateUri($uid, ['ADMCMD_prev' => $previewKeyword, '_language' => $language], ''), $uid);
->getFrontendUrlForPage((string)$uri, $uid);

} catch (SiteNotFoundException | InvalidRouteArgumentsException $e) {
throw new UnableToLinkToPageException('The page ' . $uid . ' had no proper connection to a site, no link could be built.', 1559794916);
throw new UnableToLinkToPageException(sprintf('The link to the page with ID "%d" could not be generated: %s', $uid, $e->getMessage()), 1559794916, $e);
}
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
"seld/jsonlint": "^1.11",
"symfony/yaml": "^6.1 || ^7.1",
"typo3/cms-form": "^14.0",
"typo3/testing-framework": "^9.0",
"typo3/coding-standards": "^0.8"
"typo3/cms-workspaces": "^14.3",
"typo3/coding-standards": "^0.8",
"typo3/testing-framework": "^9.0"
},
"conflict": {
"typo3/cms-core": "<14.0"
Expand Down