[TASK] Remove unused properties from EditDocumentController
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 28 Apr 2021 20:34:10 +0000 (22:34 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 1 May 2021 17:44:56 +0000 (19:44 +0200)
The values "_serialNumber", "_scrollPosition", "viewId_addParams"
are hidden form fields that are relics from TYPO3 Core v3.x,
long unused and obsolete.

Same goes for "uc" which just parks an incoming value (where
the FormEngineUtility::updateInlineView() can also be moved
inside the EditDocumentController), and unused values such as
"newC".

Resolves: #94009
Releases: master
Change-Id: I049a3f2b656affaa7860ad2ca4a9746438739881
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68902
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Jochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/backend/Classes/Form/Utility/FormEngineUtility.php

index 62702b4..7026ecb 100644 (file)
@@ -168,14 +168,6 @@ class EditDocumentController
      */
     protected $returnNewPageId = false;
 
-    /**
-     * Updated values for backendUser->uc. Used for new inline records to mark them
-     * as expanded: uc[inlineView][...]
-     *
-     * @var array|null
-     */
-    protected $uc;
-
     /**
      * ID for displaying the page in the frontend, "save and view"
      *
@@ -316,13 +308,6 @@ class EditDocumentController
      */
     protected $errorC;
 
-    /**
-     * Counter, used to count the number of new record forms displayed
-     *
-     * @var int
-     */
-    protected $newC;
-
     /**
      * Is set to the pid value of the last shown record - thus indicating which page to
      * show when clicking the SAVE/VIEW button
@@ -331,13 +316,6 @@ class EditDocumentController
      */
     protected $viewId;
 
-    /**
-     * Is set to additional parameters (like "&L=xxx") if the record supports it.
-     *
-     * @var string
-     */
-    protected $viewId_addParams;
-
     /**
      * @var FormResultCompiler
      */
@@ -459,7 +437,6 @@ class EditDocumentController
         $this->closeDoc = (int)($parsedBody['closeDoc'] ?? $queryParams['closeDoc'] ?? self::DOCUMENT_CLOSE_MODE_DEFAULT);
         $this->doSave = (bool)($parsedBody['doSave'] ?? $queryParams['doSave'] ?? false);
         $this->returnEditConf = (bool)($parsedBody['returnEditConf'] ?? $queryParams['returnEditConf'] ?? false);
-        $this->uc = $parsedBody['uc'] ?? $queryParams['uc'] ?? null;
 
         // Set overrideVals as default values if defVals does not exist.
         // @todo: Why?
@@ -593,7 +570,7 @@ class EditDocumentController
         // If there was saved any new items, load them:
         if (!empty($tce->substNEWwithIDs_table)) {
             // Save the expanded/collapsed states for new inline records, if any
-            FormEngineUtility::updateInlineView($this->uc, $tce);
+            $this->updateInlineView($request->getParsedBody()['uc'] ?? $request->getQueryParams()['uc'] ?? null, $tce);
             $newEditConf = [];
             foreach ($this->editconf as $tableName => $tableCmds) {
                 $keys = array_keys($tce->substNEWwithIDs_table, $tableName);
@@ -716,7 +693,7 @@ class EditDocumentController
                 $relatedPageId = -$nRec['t3ver_oid'];
             }
 
-            /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $duplicateTce */
+            /** @var DataHandler $duplicateTce */
             $duplicateTce = GeneralUtility::makeInstance(DataHandler::class);
 
             $duplicateCmd = [
@@ -1060,7 +1037,6 @@ class EditDocumentController
         // Initialize variables
         $this->elementsData = [];
         $this->errorC = 0;
-        $this->newC = 0;
         $editForm = '';
         $beUser = $this->getBackendUser();
         // Traverse the GPvar edit array tables
@@ -1085,7 +1061,6 @@ class EditDocumentController
 
                                 // Reset viewId - it should hold data of last entry only
                                 $this->viewId = 0;
-                                $this->viewId_addParams = '';
 
                                 $formDataCompilerInput = [
                                     'tableName' => $table,
@@ -1113,13 +1088,6 @@ class EditDocumentController
                                         $this->viewId = $formData['databaseRow']['uid'];
                                     } elseif (!empty($formData['parentPageRow']['uid'])) {
                                         $this->viewId = $formData['parentPageRow']['uid'];
-                                        // Adding "&L=xx" if the record being edited has a languageField with a value larger than zero!
-                                        if (!empty($formData['processedTca']['ctrl']['languageField'])
-                                            && is_array($formData['databaseRow'][$formData['processedTca']['ctrl']['languageField']])
-                                            && $formData['databaseRow'][$formData['processedTca']['ctrl']['languageField']][0] > 0
-                                        ) {
-                                            $this->viewId_addParams = '&L=' . $formData['databaseRow'][$formData['processedTca']['ctrl']['languageField']][0];
-                                        }
                                     }
                                 }
 
@@ -1202,7 +1170,6 @@ class EditDocumentController
                                         . '<input type="hidden"'
                                         . ' name="data[' . htmlspecialchars($table) . '][' . htmlspecialchars($formData['databaseRow']['uid']) . '][pid]"'
                                         . ' value="' . (int)$formData['databaseRow']['pid'] . '" />';
-                                    $this->newC++;
                                 }
 
                                 $editForm .= $html;
@@ -1936,18 +1903,54 @@ class EditDocumentController
             <input type="hidden" name="viewUrl" value="' . htmlspecialchars($this->viewUrl) . '" />
             <input type="hidden" name="popViewId" value="' . htmlspecialchars((string)$this->viewId) . '" />
             <input type="hidden" name="closeDoc" value="0" />
-            <input type="hidden" name="doSave" value="0" />
-            <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
-            <input type="hidden" name="_scrollPosition" value="" />';
+            <input type="hidden" name="doSave" value="0" />';
         if ($this->returnNewPageId) {
             $formContent .= '<input type="hidden" name="returnNewPageId" value="1" />';
         }
-        if ($this->viewId_addParams) {
-            $formContent .= '<input type="hidden" name="popViewId_addParams" value="' . htmlspecialchars($this->viewId_addParams) . '" />';
-        }
         return $formContent;
     }
 
+    /**
+     * Update expanded/collapsed states on new inline records if any within backendUser->uc.
+     *
+     * @param array|null $uc The uc array to be processed and saved - uc[inlineView][...]
+     * @param DataHandler $dataHandler Instance of DataHandler that saved data before
+     */
+    protected function updateInlineView($uc, DataHandler $dataHandler)
+    {
+        $backendUser = $this->getBackendUser();
+        if (!isset($uc['inlineView']) || !is_array($uc['inlineView'])) {
+            return;
+        }
+        $inlineView = (array)json_decode(is_string($backendUser->uc['inlineView']) ? $backendUser->uc['inlineView'] : '', true);
+        foreach ($uc['inlineView'] as $topTable => $topRecords) {
+            foreach ($topRecords as $topUid => $childElements) {
+                foreach ($childElements as $childTable => $childRecords) {
+                    $uids = array_keys($dataHandler->substNEWwithIDs_table, $childTable);
+                    if (!empty($uids)) {
+                        $newExpandedChildren = [];
+                        foreach ($childRecords as $childUid => $state) {
+                            if ($state && in_array($childUid, $uids)) {
+                                $newChildUid = $dataHandler->substNEWwithIDs[$childUid];
+                                $newExpandedChildren[] = $newChildUid;
+                            }
+                        }
+                        // Add new expanded child records to UC (if any):
+                        if (!empty($newExpandedChildren)) {
+                            $inlineViewCurrent = &$inlineView[$topTable][$topUid][$childTable];
+                            if (is_array($inlineViewCurrent)) {
+                                $inlineViewCurrent = array_unique(array_merge($inlineViewCurrent, $newExpandedChildren));
+                            } else {
+                                $inlineViewCurrent = $newExpandedChildren;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        $backendUser->uc['inlineView'] = json_encode($inlineView);
+        $backendUser->writeUC();
+    }
     /**
      * Returns if delete for the current table is disabled by configuration.
      * For sys_file_metadata in default language delete is always disabled.
index 217bcdf..f257696 100644 (file)
@@ -16,7 +16,6 @@
 namespace TYPO3\CMS\Backend\Form\Utility;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -137,48 +136,6 @@ class FormEngineUtility
             . '</span>';
     }
 
-    /**
-     * Update expanded/collapsed states on new inline records if any.
-     *
-     * @param array $uc The uc array to be processed and saved (by reference)
-     * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tce Instance of FormEngine that saved data before
-     * @internal
-     */
-    public static function updateInlineView(&$uc, $tce)
-    {
-        $backendUser = static::getBackendUserAuthentication();
-        if (isset($uc['inlineView']) && is_array($uc['inlineView'])) {
-            $inlineView = (array)json_decode($backendUser->uc['inlineView'], true);
-            foreach ($uc['inlineView'] as $topTable => $topRecords) {
-                foreach ($topRecords as $topUid => $childElements) {
-                    foreach ($childElements as $childTable => $childRecords) {
-                        $uids = array_keys($tce->substNEWwithIDs_table, $childTable);
-                        if (!empty($uids)) {
-                            $newExpandedChildren = [];
-                            foreach ($childRecords as $childUid => $state) {
-                                if ($state && in_array($childUid, $uids)) {
-                                    $newChildUid = $tce->substNEWwithIDs[$childUid];
-                                    $newExpandedChildren[] = $newChildUid;
-                                }
-                            }
-                            // Add new expanded child records to UC (if any):
-                            if (!empty($newExpandedChildren)) {
-                                $inlineViewCurrent = &$inlineView[$topTable][$topUid][$childTable];
-                                if (is_array($inlineViewCurrent)) {
-                                    $inlineViewCurrent = array_unique(array_merge($inlineViewCurrent, $newExpandedChildren));
-                                } else {
-                                    $inlineViewCurrent = $newExpandedChildren;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            $backendUser->uc['inlineView'] = json_encode($inlineView);
-            $backendUser->writeUC();
-        }
-    }
-
     /**
      * Compatibility layer for methods not in FormEngine scope.
      *
@@ -212,12 +169,4 @@ class FormEngineUtility
         }
         return $newRow;
     }
-
-    /**
-     * @return BackendUserAuthentication
-     */
-    protected static function getBackendUserAuthentication()
-    {
-        return $GLOBALS['BE_USER'];
-    }
 }