[BUGFIX] Allow linking to a targetSite without currentSite 97/58397/2
authorSusanne Moog <susanne.moog@typo3.org>
Wed, 26 Sep 2018 08:49:15 +0000 (10:49 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Thu, 27 Sep 2018 13:09:24 +0000 (15:09 +0200)
In case no current site exists in a context (for example currently
eID or other scripting contexts), the pageLinkBuilder threw an error
when linking to a page with a site configuration. The necessity for
having a current site config has been removed, the pageLinkBuilder
can now be used without a current site object and will then always
generate absolute URLs to the target site.

Resolves: #86384
Releases: master
Change-Id: Id8c984c4ac3837d7b4da37a99d43410c6db34187
Reviewed-on: https://review.typo3.org/58397
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Tested-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php

index f440829..36607a5 100644 (file)
@@ -332,7 +332,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
         $currentSiteLanguage = $this->getCurrentSiteLanguage();
         // Happens when currently on a pseudo-site configuration
         // We assume to use the default language then
-        if (!($currentSiteLanguage instanceof SiteLanguage)) {
+        if ($currentSite && !($currentSiteLanguage instanceof SiteLanguage)) {
             $currentSiteLanguage = $currentSite->getDefaultLanguage();
         }
 
@@ -352,9 +352,11 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
         // Use the config option to override this.
         $useAbsoluteUrl = $conf['forceAbsoluteUrl'] ?? false;
         // Check if the current page equal to the site of the target page, now only set the absolute URL
-        if ($currentSite->getRootPageId() !== $siteOfTargetPage->getRootPageId()) {
-            $useAbsoluteUrl = true;
-        } elseif ($siteLanguageOfTargetPage->getBase()->getHost() !== $currentSiteLanguage->getBase()->getHost()) {
+        // Always generate absolute URLs if no current site is set
+        if (
+            !$currentSite
+            || $currentSite->getRootPageId() !== $siteOfTargetPage->getRootPageId()
+            || $siteLanguageOfTargetPage->getBase()->getHost() !== $currentSiteLanguage->getBase()->getHost()) {
             $useAbsoluteUrl = true;
         }