Project

General

Profile

Actions

Bug #91328

closed

PageLinkBuilder creates broken "translated" Slugs for MountPoints

Added by Steffen Hastädt over 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Site Handling, Site Sets & Routing
Start date:
2020-05-07
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.3
Tags:
Complexity:
medium
Is Regression:
Yes
Sprint Focus:

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

Actions #1

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.

Actions #2

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.

Actions #3

Updated by Steffen Hastädt over 4 years ago

I'm not sure but maybe this should be solved in the pages repository.

Actions #4

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);

Actions #5

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.

Actions #6

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

Actions #7

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

Actions #8

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

Actions #9

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

Actions #10

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

Actions #11

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

Actions #12

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

Actions #13

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

Actions #14

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

Actions #15

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

Actions #16

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

Actions #17

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

Actions #18

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

Actions #19

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

Actions #20

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

Actions #21

Updated by Anonymous almost 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #22

Updated by Benni Mack almost 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF