[BUGFIX] Create proper FE links in Web->View module 57/58157/7
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 3 Sep 2018 19:40:11 +0000 (21:40 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 3 Sep 2018 20:41:32 +0000 (22:41 +0200)
Resolves: #86124
Releases: master
Change-Id: Icb706e585af8e0c0acd993f15d17276024bc5503
Reviewed-on: https://review.typo3.org/58157
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/viewpage/Classes/Controller/ViewModuleController.php

index 2fd0133..c5d2454 100644 (file)
@@ -29,6 +29,8 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Routing\PageUriBuilder;
+use TYPO3\CMS\Core\Routing\SiteMatcher;
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
@@ -150,11 +152,10 @@ class ViewModuleController
     {
         $pageId = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
         $languageId = $this->getCurrentLanguage($pageId, $request->getParsedBody()['language'] ?? $request->getQueryParams()['language'] ?? null);
-        $isHttps = $request->getAttribute('normalizedParams')->isHttps();
 
         $this->initializeView('show');
 
-        $targetUrl = $this->getTargetUrl($pageId, $languageId, $isHttps);
+        $targetUrl = $this->getTargetUrl($pageId, $languageId);
         $this->registerDocHeader($pageId, $languageId, $targetUrl);
 
         $this->moduleTemplate->setBodyTag('<body class="typo3-module-viewpage">');
@@ -195,41 +196,43 @@ class ViewModuleController
      *
      * @param int $pageId
      * @param int $languageId
-     * @param bool $isHttps
      * @return string
      */
-    protected function getTargetUrl(int $pageId, int $languageId, bool $isHttps): string
+    protected function getTargetUrl(int $pageId, int $languageId): string
     {
         $permissionClause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
         $pageRecord = BackendUtility::readPageAccess($pageId, $permissionClause);
         if ($pageRecord) {
             $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord);
-
-            $adminCommand = $this->getAdminCommand($pageId);
-            $domainName = $this->getDomainName($pageId);
-            $languageParameter = $languageId ? '&L=' . $languageId : '';
+            $rootLine = BackendUtility::BEgetRootLine($pageId);
             // Mount point overlay: Set new target page id and mp parameter
             $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
-            $mountPointMpParameter = '';
+            $additionalGetVars = $this->getAdminCommand($pageId);
+            $siteMatcher = GeneralUtility::makeInstance(SiteMatcher::class);
+            $site = $siteMatcher->matchByPageId($pageId, $rootLine);
             $finalPageIdToShow = $pageId;
             $mountPointInformation = $pageRepository->getMountPointInfo($pageId);
             if ($mountPointInformation && $mountPointInformation['overlay']) {
                 // New page id
                 $finalPageIdToShow = $mountPointInformation['mount_pid'];
-                $mountPointMpParameter = '&MP=' . $mountPointInformation['MPvar'];
-            }
-            // Modify relative path to protocol with host if domain record is given
-            $protocolAndHost = '..';
-            if ($domainName) {
-                // TCEMAIN.previewDomain can contain the protocol, check prevents double protocol URLs
-                if (strpos($domainName, '://') !== false) {
-                    $protocolAndHost = $domainName;
-                } else {
-                    $protocol = $isHttps ? 'https' : 'http';
-                    $protocolAndHost = $protocol . '://' . $domainName;
-                }
+                $additionalGetVars .= '&MP=' . $mountPointInformation['MPvar'];
             }
-            return $protocolAndHost . '/index.php?id=' . $finalPageIdToShow . $this->getTypeParameterIfSet($finalPageIdToShow) . $mountPointMpParameter . $adminCommand . $languageParameter;
+            $additionalGetVars .= $this->getTypeParameterIfSet($finalPageIdToShow);
+            $additionalQueryParams = [];
+            parse_str($additionalGetVars, $additionalQueryParams);
+            $options = [
+                'site' => $site,
+                'rootLine' => $rootLine,
+                'language' => $languageId,
+            ];
+            $uriBuilder = GeneralUtility::makeInstance(PageUriBuilder::class);
+            return (string)$uriBuilder->buildUri(
+                $finalPageIdToShow,
+                $additionalQueryParams,
+                '',
+                $options,
+                $uriBuilder::ABSOLUTE_URL
+            );
         }
         return '#';
     }