From 2e9f2b7c169ebd2cb0afab972177f00f00e1d76c Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Fri, 14 Feb 2020 10:40:27 +0100
Subject: [PATCH] [TASK] Remove option content_from_pid_allowOutsideDomain

Due to site handling the TypoScript option content_from_pid_allowOutsideDomain
is not needed anymore, and can be removed, as it does not have any effect on
the result. This was domain-specific in combination with sys_domain
and ?id=123.

Resolves: #90371
Releases: master
Change-Id: I90d6089af2461d4f605e7ff6778ccf36e008c537
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63238
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
---
 ...ent_from_pid_allowOutsideDomainRemoved.rst | 19 ++++++++++
 .../TypoScriptFrontendController.php          | 37 +++++++++++++------
 .../t3editor/Resources/Private/tsref.xml      |  5 ---
 .../JavaScript/Mode/typoscript/typoscript.js  |  1 -
 4 files changed, 44 insertions(+), 18 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Important-90371-TypoScriptOptionConfigcontent_from_pid_allowOutsideDomainRemoved.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-90371-TypoScriptOptionConfigcontent_from_pid_allowOutsideDomainRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-90371-TypoScriptOptionConfigcontent_from_pid_allowOutsideDomainRemoved.rst
new file mode 100644
index 000000000000..6a652eb150a3
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Important-90371-TypoScriptOptionConfigcontent_from_pid_allowOutsideDomainRemoved.rst
@@ -0,0 +1,19 @@
+.. include:: ../../Includes.txt
+
+========================================================================================
+Important: #90371 - TypoScript option config.content_from_pid_allowOutsideDomain removed
+========================================================================================
+
+See :issue:`90371`
+
+Description
+===========
+
+TYPO3's Site Handling - introduced in TYPO3 v9 - allows for defining
+multiple sites within one installation, whereas before all configuration was based on domain records. The TypoScript option `config.content_from_pid_allowOutsideDomain` was used to limit
+the page property option "Show content from this page instead" (pages.content_from_pid) to be evaluated outside of the current page
+tree which was ineffective since the usage of Site Handling.
+
+The option serves no purpose anymore and has been removed.
+
+.. index:: Frontend, TypoScript, ext:frontend
\ No newline at end of file
diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index aa3165932e0d..061523b3e998 100644
--- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
@@ -1702,8 +1702,8 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     public function getPageAndRootlineWithDomain($rootPageId)
     {
         $this->getPageAndRootline();
-        // Checks if the $domain-startpage is in the rootLine. This is necessary so that references to page-id's from other domains are not possible.
-        if ($rootPageId && is_array($this->rootLine) && $this->rootLine !== []) {
+        // Checks if the $domain-startpage is in the rootLine. This is necessary so that references to page-id's via ?id=123 from other sites are not possible.
+        if (is_array($this->rootLine) && $this->rootLine !== []) {
             $idFound = false;
             foreach ($this->rootLine as $key => $val) {
                 if ($val['uid'] == $rootPageId) {
@@ -2699,6 +2699,28 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         $this->no_cacheBeforePageGen = $this->no_cache;
     }
 
+    /**
+     * Check the value of "content_from_pid" of the current page record, and see if the current request
+     * should actually show content from another page.
+     *
+     * By using $TSFE->getPageAndRootline() on the cloned object, all rootline restrictions (extendToSubPages)
+     * are evaluated as well.
+     *
+     * @return int the current page ID or another one if resolved properly - usually set to $this->contentPid
+     */
+    protected function resolveContentPid(): int
+    {
+        if (!isset($this->page['content_from_pid']) || empty($this->page['content_from_pid'])) {
+            return (int)$this->id;
+        }
+        // make REAL copy of TSFE object - not reference!
+        $temp_copy_TSFE = clone $this;
+        // Set ->id to the content_from_pid value - we are going to evaluate this pid as was it a given id for a page-display!
+        $temp_copy_TSFE->id = $this->page['content_from_pid'];
+        $temp_copy_TSFE->MP = '';
+        $temp_copy_TSFE->getPageAndRootline();
+        return (int)$temp_copy_TSFE->id;
+    }
     /**
      * Sets up TypoScript "config." options and set properties in $TSFE.
      *
@@ -2707,16 +2729,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     public function preparePageContentGeneration(ServerRequestInterface $request)
     {
         $this->getTimeTracker()->push('Prepare page content generation');
-        if (isset($this->page['content_from_pid']) && $this->page['content_from_pid'] > 0) {
-            // make REAL copy of TSFE object - not reference!
-            $temp_copy_TSFE = clone $this;
-            // Set ->id to the content_from_pid value - we are going to evaluate this pid as was it a given id for a page-display!
-            $temp_copy_TSFE->id = $this->page['content_from_pid'];
-            $temp_copy_TSFE->MP = '';
-            $temp_copy_TSFE->getPageAndRootlineWithDomain($this->config['config']['content_from_pid_allowOutsideDomain'] ? 0 : $this->site->getRootPageId());
-            $this->contentPid = (int)$temp_copy_TSFE->id;
-            unset($temp_copy_TSFE);
-        }
+        $this->contentPid = $this->resolveContentPid();
         // Global vars...
         $this->indexedDocTitle = $this->page['title'] ?? null;
         // Base url:
diff --git a/typo3/sysext/t3editor/Resources/Private/tsref.xml b/typo3/sysext/t3editor/Resources/Private/tsref.xml
index 1ee0b6bfdf1f..30b2ca5cd367 100644
--- a/typo3/sysext/t3editor/Resources/Private/tsref.xml
+++ b/typo3/sysext/t3editor/Resources/Private/tsref.xml
@@ -271,11 +271,6 @@ config.cache.all = fe_users:2]]></description>
 This value is overridden by the value set in the page-record (field="cache_timeout") if this value is greater than zero.]]></description>
 			<default><![CDATA[86400 (=24H)]]></default>
 		</property>
-		<property name="content_from_pid_allowOutsideDomain" type="boolean">
-			<description><![CDATA[Using the "Show content from this page instead" feature allows you to insert content from the current domain only. Setting this option will allow content included from anywhere in the page tree!]]></description>
-			<default><![CDATA[
-]]></default>
-		</property>
 		<property name="contentObjectExceptionHandler" type="array">
 			<description><![CDATA[Exceptions which occur during rendering of content objects (typically plugins) will now be caught by default in production context and an error message is shown along with the rendered output.
 
diff --git a/typo3/sysext/t3editor/Resources/Public/JavaScript/Mode/typoscript/typoscript.js b/typo3/sysext/t3editor/Resources/Public/JavaScript/Mode/typoscript/typoscript.js
index 2ea1e1d6e83f..36b765157df3 100644
--- a/typo3/sysext/t3editor/Resources/Public/JavaScript/Mode/typoscript/typoscript.js
+++ b/typo3/sysext/t3editor/Resources/Public/JavaScript/Mode/typoscript/typoscript.js
@@ -202,7 +202,6 @@
         'constants': kw('constants'),
         'CONTENT': kw('CONTENT'),
         'content': A,
-        'content_from_pid_allowOutsideDomain': kw('content_from_pid_allowOutsideDomain'),
         'contextMenu': kw('contextMenu'),
         'copy': A,
         'copyLevels': kw('copyLevels'),
-- 
GitLab