Issue Bug Closed

#102161f:link.page and f:uri.page (UriBuilder) are impossible to use with language ID because of internals of PageLinkBuilder

Claus Due 10/13/23, 09:40 updated 08/16/26, 12:51

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

History 57

  1. Claus Due commented <span data-processor="relativetime" data-value="2023-10-13T10:18:01+00:00" > 10/13/23, 10:18 </span>

    s/$conf[‘language’]/$configuration[‘language’]

  2. Benni Mack commented and changed status Under Review Needs 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?

  3. Georg Ringer commented and changed status Needs Feedback Closed <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!