Actions
Bug #102161
openf:link.page and f:uri.page (UriBuilder) are impossible to use with language ID because of internals of PageLinkBuilder
Status:
New
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2023-10-13
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
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.
Actions