Project

General

Profile

Actions

Bug #102161

open

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

Added by Claus Due 6 months ago. Updated 6 months ago.

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.


Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Story #101566: Extbase related translation issuesNew2023-08-03

Actions
Actions #1

Updated by Claus Due 6 months ago

s/$conf['language']/$configuration['language']

Actions #2

Updated by Astrid Haubold 6 months ago

  • Related to Story #101566: Extbase related translation issues added
Actions

Also available in: Atom PDF