From 7e8a4b400c8183e3c6d1890f7bf40f6ffe620c34 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Sat, 16 Apr 2022 01:33:55 +0200
Subject: [PATCH] [TASK] Use constants in NewMultiplePagesController
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This change uses constants from PageRepository
to define possible doktypes.

In addition, some minor details in the rest
of the code (strict types, variable renaming)
help to understand the code better.

Resolves: #97399
Releases: main
Change-Id: Id275edc131b2406f346418eecc099fd1f0b2ac05
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74328
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../Page/NewMultiplePagesController.php       | 34 +++++++++----------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/Page/NewMultiplePagesController.php b/typo3/sysext/backend/Classes/Controller/Page/NewMultiplePagesController.php
index 352f2433b4f9..d63b2ddc8831 100644
--- a/typo3/sysext/backend/Classes/Controller/Page/NewMultiplePagesController.php
+++ b/typo3/sysext/backend/Classes/Controller/Page/NewMultiplePagesController.php
@@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\Domain\Repository\PageRepository;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Localization\LanguageService;
@@ -136,30 +137,30 @@ class NewMultiplePagesController
             }
         }
 
-        $commandArray = [];
+        $dataMap = [];
         $firstRecord = true;
         $previousIdentifier = '';
         foreach ($newPagesData as $identifier => $data) {
             if (!trim($data['title'])) {
                 continue;
             }
-            $commandArray['pages'][$identifier]['hidden'] = (int)$hidePages;
-            $commandArray['pages'][$identifier]['nav_hide'] = (int)$hidePagesInMenu;
-            $commandArray['pages'][$identifier]['title'] = $data['title'];
-            $commandArray['pages'][$identifier]['doktype'] = $data['doktype'];
+            $dataMap['pages'][$identifier]['hidden'] = (int)$hidePages;
+            $dataMap['pages'][$identifier]['nav_hide'] = (int)$hidePagesInMenu;
+            $dataMap['pages'][$identifier]['title'] = $data['title'];
+            $dataMap['pages'][$identifier]['doktype'] = $data['doktype'];
             if ($firstRecord) {
                 $firstRecord = false;
-                $commandArray['pages'][$identifier]['pid'] = $firstPid;
+                $dataMap['pages'][$identifier]['pid'] = $firstPid;
             } else {
-                $commandArray['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
+                $dataMap['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
             }
             $previousIdentifier = $identifier;
         }
 
-        if (!empty($commandArray)) {
+        if (!empty($dataMap)) {
             $pagesCreated = true;
             $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
-            $dataHandler->start($commandArray, []);
+            $dataHandler->start($dataMap, []);
             $dataHandler->process_datamap();
             BackendUtility::setUpdateSignal('updatePageTree');
         }
@@ -169,11 +170,8 @@ class NewMultiplePagesController
 
     /**
      * Page selector type data
-     *
-     * @param int $pageUid Page Uid
-     * @return array
      */
-    protected function getTypeSelectData(int $pageUid)
+    protected function getTypeSelectData(int $pageUid): array
     {
         $tsConfig = BackendUtility::getPagesTSconfig($pageUid);
         $pagesTsConfig = $tsConfig['TCEFORM.']['pages.'] ?? [];
@@ -182,11 +180,11 @@ class NewMultiplePagesController
         $types = $GLOBALS['PAGES_TYPES'];
         unset($types['default']);
         $types = array_keys($types);
-        $types[] = 1; // default
-        $types[] = 3; // link
-        $types[] = 4; // shortcut
-        $types[] = 7; // mount point
-        $types[] = 199; // spacer
+        $types[] = PageRepository::DOKTYPE_DEFAULT;
+        $types[] = PageRepository::DOKTYPE_LINK;
+        $types[] = PageRepository::DOKTYPE_SHORTCUT;
+        $types[] = PageRepository::DOKTYPE_MOUNTPOINT;
+        $types[] = PageRepository::DOKTYPE_SPACER;
 
         if (!$this->getBackendUser()->isAdmin() && isset($this->getBackendUser()->groupData['pagetypes_select'])) {
             $types = GeneralUtility::trimExplode(',', $this->getBackendUser()->groupData['pagetypes_select'], true);
-- 
GitLab