Bug #102161
openf:link.page and f:uri.page (UriBuilder) are impossible to use with language ID because of internals of PageLinkBuilder
0%
Description
There is a conflict in the internal type requirements of the "language" argument on UriBuilder and PageLinkBuilder:
- If you do what UriBuilder says and pass the language ID as a string, you get `TYPO3\CMS\Core\Context\LanguageAspect::__construct(): Argument #1 ($id) must be of type int, string given, called in cms-frontend/Classes/Typolink/PageLinkBuilder.php on line 416`.
- If you do what this error message implies and pass language ID as an integer, you get `TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::setLanguage(): Argument #1 ($language) must be of type ?string, int given, called in cms-fluid/Classes/ViewHelpers/Link/PageViewHelper.php on line 261`.
The result is a deadlock where it is impossible to specify the desired language when creating a link through UriBuilder.
The problem is in \TYPO3\CMS\Frontend\Typolink\PageLinkBuilder::resolvePage, which indiscriminately uses the $configuration['language'] variable and assumes it's an integer (if it is not a string "current") and passes this value to the constructor of LanguageAspect.
The right solution is to do what the build() method on PageLinkBuilder does:
if (isset($configuration['language']) && $configuration['language'] !== 'current') {
$siteOfTargetPage = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId((int)$page['uid']);
$siteLanguageOfTargetPage = $this->getSiteLanguageOfTargetPage($siteOfTargetPage, (string)($conf['language'] ?? 'current'));
$languageAspect = LanguageAspectFactory::createFromSiteLanguage($siteLanguageOfTargetPage);
$page = $pageRepository->getLanguageOverlay('pages', $page, $languageAspect);
}
This would also have the side effect of actually respecting language fallback when resolving the translated version of a page.
Updated by Claus Due about 1 year ago
s/$conf['language']/$configuration['language']
Updated by Astrid Haubold about 1 year ago
- Related to Story #101566: Extbase related translation issues added
Updated by Gerrit Code Review 1 day ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/87420