1

Consider for a moment the following pagetree:

  • Website A (root page with domain record a.example.com)
    • Page A
      • Page A.1
    • Page B
    • Page C
  • Website B (root page with domain record b.example.com)
    • Page X
      • Page Y (mountpoint of "Page A", with content from that page)

To generate canonical URLs, I need to get the absolute URL from the original page. I am doing that in a typoscript userfunc on "Page X", but something seems to be wrong:

This returns the uid of Page A, not Page X:

$GLOBALS['TSFE']->page['uid'];

But this does not return the expected URL "a.example.com/page-a/" but rather "b.example.com/page-x/page-y":

$GLOBALS['TSFE']->cObj->typoLink_URL([
    'parameter' => $GLOBALS['TSFE']->page['uid'],
    'forceAbsoluteUrl' => 1
]);

Obviously, TYPO3 still somehow uses the domain of the page the user is currently on, instead of the original domain where "Page A" is actually located.

For completions sake, here some values I already set in my setup.txt:

config {
    absRefPrefix = /
    content_from_pid_allowOutsideDomain = 1
    typolinkCheckRootline = 1
    typolinkEnableLinksAcrossDomains = 1
}

The question is: How can I get the original URL for the uid of Page A?

Lars Ebert
  • 3,487
  • 2
  • 24
  • 46

1 Answers1

-1

With a few more hours, I found a very simple way to generate the original URL without mountpoints:

$tsfe = clone $GLOBALS['TSFE'];
$tsfe->MP = '';
$cObj = new ContentObjectRenderer($tsfe);
$url = $cObj->typolink_URL(array('parameter' => $uid, 'forceAbsoluteUrl' => 1));

In short, instead of using the original TypoScriptFrontendController, which contains the mountpoint, I simply clone it, remove the mountpoint and then generate the url through a new ContentObjectRenderer created by that modified TypoScriptFrontendController.

Lars Ebert
  • 3,487
  • 2
  • 24
  • 46
  • I would really appreciate feedback as a comment from whoever downvoted. I know this solution is a bit dirty, but it was the only way I could get it to work. If you know a better/cleaner version, feel free to post an answer yourself. Or at the very least let me know why you deem my answer downvote worthy as a comment. – Lars Ebert Jul 29 '16 at 10:07