From 1b61775eb0ee39ea6113708d886bd792ea358680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wolda=C5=84ski?= Date: Tue, 12 May 2026 16:19:42 +0200 Subject: [PATCH] [BUGFIX] Fix issue with readonly class Resolves #887 --- Classes/XClass/Preview/PreviewUriBuilder.php | 34 +++++++------------- composer.json | 5 +-- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Classes/XClass/Preview/PreviewUriBuilder.php b/Classes/XClass/Preview/PreviewUriBuilder.php index 70bcebb0..65d48b43 100644 --- a/Classes/XClass/Preview/PreviewUriBuilder.php +++ b/Classes/XClass/Preview/PreviewUriBuilder.php @@ -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); } } } diff --git a/composer.json b/composer.json index f7c2817f..073ddc3a 100644 --- a/composer.json +++ b/composer.json @@ -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"