From 0e20484c0e1355cf02d0b7a88327bedca24116e6 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Fri, 13 Jul 2018 23:04:09 +0200
Subject: [PATCH] [TASK] Deprecate cObj->enableFields()

The method is just a wrapper for PageRepository->enableFields()
which should be used instead.

Resolves: #85558
Releases: master
Change-Id: I5fd18ef3e101325bc95f4d0147899d961f5898f6
Reviewed-on: https://review.typo3.org/57598
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
---
 ...558-ContentObjectRenderer-enableFields.rst | 34 +++++++++++++++++++
 .../ContentObject/ContentObjectRenderer.php   |  4 ++-
 .../Menu/AbstractMenuContentObject.php        |  2 +-
 .../ContentObject/RecordsContentObject.php    | 15 ++++++--
 .../Php/MethodCallMatcher.php                 |  7 ++++
 5 files changed, 57 insertions(+), 5 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85558-ContentObjectRenderer-enableFields.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85558-ContentObjectRenderer-enableFields.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85558-ContentObjectRenderer-enableFields.rst
new file mode 100644
index 000000000000..8a7581456184
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85558-ContentObjectRenderer-enableFields.rst
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=========================================================
+Deprecation: #85558 - ContentObjectRenderer->enableFields
+=========================================================
+
+See :issue:`85558`
+
+Description
+===========
+
+The public method :php:`TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->enableFields` has been marked as
+deprecated.
+
+
+Impact
+======
+
+Calling the method directly will trigger a deprecation message.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with custom extensions calling this method directly.
+
+
+Migration
+=========
+
+As :php:`enableFields()` acts as a simple wrapper around :php:`PageRepository->enableFields()`, it is recommended
+to instantiate PageRepository directly.
+
+.. index:: Frontend, PHP-API, FullyScanned, ext:frontend
\ No newline at end of file
diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
index c2c3d2e2b236..358916812d9c 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
@@ -6064,9 +6064,11 @@ class ContentObjectRenderer implements LoggerAwareInterface
      * @param bool $show_hidden If set, then you want NOT to filter out hidden records. Otherwise hidden record are filtered based on the current preview settings.
      * @param array $ignore_array Array you can pass where keys can be "disabled", "starttime", "endtime", "fe_group" (keys from "enablefields" in TCA) and if set they will make sure that part of the clause is not added. Thus disables the specific part of the clause. For previewing etc.
      * @return string The part of the where clause on the form " AND [fieldname]=0 AND ...". Eg. " AND hidden=0 AND starttime < 123345567
+     * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0.
      */
     public function enableFields($table, $show_hidden = false, array $ignore_array = [])
     {
+        trigger_error('cObj->enableFields() will be removed in TYPO3 v10. should be used from the PageRepository->enableFields() functionality directly.', E_USER_DEPRECATED);
         return $this->getTypoScriptFrontendController()->sys_page->enableFields($table, $show_hidden ? true : -1, $ignore_array);
     }
 
@@ -6825,7 +6827,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
             $constraints[] = QueryHelper::stripLogicalOperatorPrefix($tsfe->sys_page->where_hid_del);
             $constraints[] = QueryHelper::stripLogicalOperatorPrefix($tsfe->sys_page->where_groupAccess);
         } else {
-            $constraints[] = QueryHelper::stripLogicalOperatorPrefix($this->enableFields($table, false, $enableFieldsIgnore));
+            $constraints[] = QueryHelper::stripLogicalOperatorPrefix($tsfe->sys_page->enableFields($table, -1, $enableFieldsIgnore));
         }
 
         // MAKE WHERE:
diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
index 9690f923c6c3..3ff5e80bff7c 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
@@ -798,7 +798,7 @@ abstract class AbstractMenuContentObject
         $loadDB = GeneralUtility::makeInstance(RelationHandler::class);
         $loadDB->setFetchAllFields(true);
         $loadDB->start($specialValue, 'pages');
-        $loadDB->additionalWhere['pages'] = $this->parent_cObj->enableFields('pages', false, $skippedEnableFields);
+        $loadDB->additionalWhere['pages'] = $this->sys_page->enableFields('pages', -1, $skippedEnableFields);
         $loadDB->getFromDB();
         $pageLinkBuilder = GeneralUtility::makeInstance(PageLinkBuilder::class, $this->parent_cObj);
         foreach ($loadDB->itemArray as $val) {
diff --git a/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php
index 979060c76c05..d6d72d89e020 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/RecordsContentObject.php
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\Category\Collection\CategoryCollection;
+use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * Contains RECORDS class object.
@@ -92,10 +93,10 @@ class RecordsContentObject extends AbstractContentObject
                     // Perform overlays if necessary (records coming from category collections are already overlaid)
                     if ($source) {
                         // Versioning preview
-                        $GLOBALS['TSFE']->sys_page->versionOL($val['table'], $row);
+                        $this->getPageRepository()->versionOL($val['table'], $row);
                         // Language overlay
                         if (is_array($row)) {
-                            $row = $GLOBALS['TSFE']->sys_page->getLanguageOverlay($val['table'], $row);
+                            $row = $this->getPageRepository()->getLanguageOverlay($val['table'], $row);
                         }
                     }
                     // Might be unset during the overlay process
@@ -149,7 +150,7 @@ class RecordsContentObject extends AbstractContentObject
         $loadDB->start($source, implode(',', $tables));
         foreach ($loadDB->tableArray as $table => $v) {
             if (isset($GLOBALS['TCA'][$table])) {
-                $loadDB->additionalWhere[$table] = $this->cObj->enableFields($table);
+                $loadDB->additionalWhere[$table] = $this->getPageRepository()->enableFields($table);
             }
         }
         $this->data = $loadDB->getFromDB();
@@ -226,4 +227,12 @@ class RecordsContentObject extends AbstractContentObject
     {
         return GeneralUtility::makeInstance(TimeTracker::class);
     }
+
+    /**
+     * @return PageRepository
+     */
+    protected function getPageRepository(): PageRepository
+    {
+        return $GLOBALS['TSFE']->sys_page ?: GeneralUtility::makeInstance(PageRepository::class);
+    }
 }
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
index 63d32942ab50..7d98d5d14f6a 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
@@ -2438,6 +2438,13 @@ return [
             'Deprecation-85555-TypoScriptFrontendController-getUniqueId.rst',
         ],
     ],
+    'TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->enableFields' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Deprecation-85558-ContentObjectRenderer-enableFields.rst'
+        ],
+    ],
     'TYPO3\CMS\Scheduler\Classes\Controller\SchedulerModuleController->addMessage' => [
         'numberOfMandatoryArguments' => 1,
         'maximumNumberOfArguments' => 2,
-- 
GitLab