Bug #91328
closedPageLinkBuilder creates broken "translated" Slugs for MountPoints
100%
Description
I have a page with language menu and MountPoints. The source pages are in a different page tree.
- current root page - Page - MountPoint (mounts Subpage) - other root page - Page - Subpage - Page - Page - Page
The links are generated by a classic TypoScript language menu:
https://docs.typo3.org/m/typo3/guide-frontendlocalization/master/en-us/LanguageMenu/Index.html
Generated with on the page with the default language the menu is generated correctly.
/en/page/subpage/
/sv/sida/delsida/
/no/page/under/
But as soon as the menu is generated on a translated page, all pages are generated with the wrong slug for the mount point.
SV:
/en/sida/delsida/
/sv/sida/delsida/
/no/sida/delsida/
NO:
/en/page/under/
/sv/page/under/
/no/page/under/
This is caused by TYPO3\CMS\Core\Routing\PageRouter::resolveMountPointParameterIntoPageSlug
In this method the target language is not respected and the slug part of the MountPoint is overwritten in the wrong language:
// Get slugs in the translated page
$mountedPage = $pageRepository->getPage($mountedPage);
$mountRoot = $pageRepository->getPage($mountRoot);
The getPage always returns the page with language overlay of the current language and results in the "translated" slug of the mount point.
More clear is this if the mount point is on a different level.
Correct menu in default language:
/en/page/mountpoint/subpage/translation
/no/page/monteringspunkt/under/oversettelse
/sv/sida/monteringspunkt/undersida/translation
Wrong overwritten part by resolveMountPointParameterIntoPageSlug:
SV:
/en/sida/monteringspunkt/subpage/translation
/no/sida/monteringspunkt/under/oversettelse
/sv/sida/monteringspunkt/undersida/translation
NO:
/en/page/monteringspunkt/subpage/translation
/no/page/monteringspunkt/under/oversettelse
/sv/page/monteringspunkt/undersida/translation
Updated by Steffen Hastädt over 4 years ago
When the current page is a translated page, $mountedPage = $pageRepository->getPage($mountedPage); can't create a language overlay.
So at the end of PageRepository::getPage the call $result = $this->getPageOverlay($row); returns the same record even if the target language is different to the page overlay since the translated page itself is not translated.
That's why it works in the default language. There is the given $row the page in the original language and it can create a translation for the given page.
Updated by Steffen Hastädt over 4 years ago
I'm sure this is not the right way but that's how I mad it work.
I added two XClasses for my project.
I couldn't find a way to get the languageAspect of the target page in the method resolveMountPointParameterIntoPageSlug. That's why I added one XClass only to add the method getLanguageAspect to the PageRepository.
\TYPO3\CMS\Frontend\Page\PageRepository
/**
* @return \TYPO3\CMS\Core\Context\AspectInterface
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
*/
public function getLanguageAspect()
{
return $this->context->getAspect('language');
}
Then I modified the method resolveMountPointParameterIntoPageSlug in the following way. There is probably a better way but...
$mountedPage = $pageRepository->getPage($mountedPage, false);
// XXX>
/** @var \TYPO3\CMS\Core\Context\LanguageAspect $langAspect */
$langAspect = $pageRepository->getLanguageAspect();
if(($langAspect->getId() === 0 || !$pageRepository->isPageSuitableForLanguage($mountedPage, $langAspect)) &&
$mountedPage["sys_language_uid"] > 0 &&
$mountedPage["l10n_parent"] > 0
) {
$mountedPage = $pageRepository->getPage($mountedPage["l10n_parent"]);
}
// <XXX
$mountRoot = $pageRepository->getPage($mountRoot, false);
Then the URLs are right in all cases. At first I only tried isPageSuitableForLanguage but this only worked if the languageId is not 0.
Updated by Steffen Hastädt over 4 years ago
I'm not sure but maybe this should be solved in the pages repository.
Updated by Aurelius Hogan over 4 years ago
I had the same problem here. But when I patched my code as Steffen did, everything looked fine on the first localization. But the second localization failed:
/en/page/subpage/
/sv/sida/delsida/
/no/page/under/
SV:
/en/page/subpage/
/sv/sida/delsida/
/no/page/under/
NO:
/en/page/subpage/
/sv/sida/under/
/no/page/under/
To fix that I changed the code on line 4 to test $langAspect->getId() does not match sys_language_uid to:
$mountedPage = $pageRepository->getPage($mountedPage, false);
/** @var \TYPO3\CMS\Core\Context\LanguageAspect $langAspect */
$langAspect = $pageRepository->getLanguageAspect();
if(($langAspect->getId() !== $mountedPage["sys_language_uid"] || !$pageRepository->isPageSuitableForLanguage($mountedPage, $langAspect)) &&
$mountedPage["sys_language_uid"] > 0 &&
$mountedPage["l10n_parent"] > 0
) {
$mountedPage = $pageRepository->getPage($mountedPage["l10n_parent"]);
}
$mountRoot = $pageRepository->getPage($mountRoot, false);
Updated by Devid Messner over 4 years ago
The problem also occurs with TYPO3 v10.
In my opinion this problem is already caused when creating the MP parameter.
I think that the "FirstPageUid" parameter should always point to the original Page-Uid and not to the Page-uid of the translation.
If I replaced the following line in TYPO3v9 at the class "PageRepository->getMountPointInfo" (line 1355)
--- PageRepository.php.orig 2020-06-30 07:29:06.140000000 +0000
+++ PageRepository.php 2020-06-30 07:29:37.110000000 +0000
@@ -1352,7 +1352,7 @@
}
// Set first Page uid:
if (!$firstPageUid) {
- $firstPageUid = $pageRec['uid'];
+ $firstPageUid = $pageRec['l10n_parent'] ? $pageRec['l10n_parent'] : $pageRec['uid'];
}
// Look for mount pid value plus other required circumstances:
$mount_pid = (int)$pageRec['mount_pid'];
then the translation of the slugs works correctly for me.
Updated by Gerrit Code Review over 4 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review over 4 years ago
Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review about 4 years ago
Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review about 4 years ago
Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review almost 4 years ago
Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64952
Updated by Gerrit Code Review almost 4 years ago
Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66756
Updated by Gerrit Code Review almost 4 years ago
Patch set 2 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66756
Updated by Anonymous almost 4 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset f8ce4c4a992ed77e67ac9f3ad43f6db288bb9806.
Updated by Benni Mack almost 4 years ago
- Status changed from Resolved to Closed