#102161f:link.page and f:uri.page (UriBuilder) are impossible to use with language ID because of internals of PageLinkBuilder
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.
Reviews 1
Related issues 2
History 57
-
Astrid Haubold changed Related to #101566 <span data-processor="relativetime" data-value="2023-10-15T17:09:12+00:00" > 10/15/23, 17:09 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 87420 status
NewUnder Review <span data-processor="relativetime" data-value="2024-12-10T15:11:27+00:00" > 12/10/24, 15:11 </span> -
Gerrit Code Review pushed patch set 2 for main to change 87420 <span data-processor="relativetime" data-value="2025-03-22T12:12:44+00:00" > 03/22/25, 12:12 </span>
-
Benni Mack changed Related to #102124 <span data-processor="relativetime" data-value="2025-03-22T19:38:19+00:00" > 03/22/25, 19:38 </span>
-
Benni Mack commented and changed status
Under ReviewNeeds Feedback <span data-processor="relativetime" data-value="2025-03-22T19:38:34+00:00" > 03/22/25, 19:38 </span>Hey,
I think this was fixed with #102124 – does it work for you?
-
Georg Ringer commented and changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2026-08-16T12:51:04+00:00" > 08/16/26, 12:51 </span>closing issue cause of lack of feedback. if this is still valid for TYPO3 13, feel free to open a new issue!
s/$conf[‘language’]/$configuration[‘language’]