From 27f0c4f8a6900abf01117ecde96d4cf0f071f426 Mon Sep 17 00:00:00 2001
From: Andreas Nedbal <andy@pixelde.su>
Date: Wed, 12 Jun 2024 17:26:52 +0200
Subject: [PATCH] [BUGFIX] Properly respect "enableClipBoard" TSconfig

With the rework of moving the "Show clipboard" toggle into the view
mode dropdown for the list and filelist module, the functionality
of the user TSconfig "options.file_list.enableClipBoard" and
the page TSconfig "mod.web_list.enableClipBoard" has been
broken. This commit fixes the functionality, aligning it with the
documented behaviours.

Resolves: #102145
Releases: main, 12.4
Change-Id: I17e3677638ea9d2f950a9f8d6c33ad089fc813c1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84642
Tested-by: Andreas Nedbal <andy@pixelde.su>
Reviewed-by: Andreas Nedbal <andy@pixelde.su>
Tested-by: core-ci <typo3@b13.com>
---
 .../Controller/RecordListController.php       |  8 +++++---
 .../Classes/Controller/FileListController.php | 20 +++++++++++++------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/RecordListController.php b/typo3/sysext/backend/Classes/Controller/RecordListController.php
index e3621b2869ef..97ffd2692134 100644
--- a/typo3/sysext/backend/Classes/Controller/RecordListController.php
+++ b/typo3/sysext/backend/Classes/Controller/RecordListController.php
@@ -114,11 +114,13 @@ class RecordListController
 
         // Check if Clipboard is allowed to be shown:
         if (($this->modTSconfig['enableClipBoard'] ?? '') === 'activated') {
-            $this->allowClipboard = true;
+            $this->allowClipboard = false;
+            $this->moduleData->set('clipBoard', true);
         } elseif (($this->modTSconfig['enableClipBoard'] ?? '') === 'selectable') {
             $this->allowClipboard = true;
         } elseif (($this->modTSconfig['enableClipBoard'] ?? '') === 'deactivated') {
             $this->allowClipboard = false;
+            $this->moduleData->set('clipBoard', false);
         }
 
         // Check if SearchBox is allowed to be shown:
@@ -155,7 +157,7 @@ class RecordListController
             $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
             $dbList->setTableDisplayOrder($typoScriptService->convertTypoScriptArrayToPlainArray($this->modTSconfig['tableDisplayOrder.']));
         }
-        $clipboard = $this->initializeClipboard($request, $this->allowClipboard && (bool)$this->moduleData->get('clipBoard'));
+        $clipboard = $this->initializeClipboard($request, (bool)$this->moduleData->get('clipBoard'));
         $dbList->clipObj = $clipboard;
         $additionalRecordListEvent = $this->eventDispatcher->dispatch(new RenderAdditionalContentToRecordListEvent($request));
 
@@ -191,7 +193,7 @@ class RecordListController
             $searchBoxHtml = $this->renderSearchBox($request, $dbList, $this->searchTerm, $search_levels);
         }
         $clipboardHtml = '';
-        if ($this->allowClipboard && $this->moduleData->get('clipBoard') && ($tableListHtml || $clipboard->hasElements())) {
+        if ($this->moduleData->get('clipBoard') && ($tableListHtml || $clipboard->hasElements())) {
             $clipboardHtml = '<hr class="spacer"><typo3-backend-clipboard-panel return-url="' . htmlspecialchars($dbList->listURL()) . '"></typo3-backend-clipboard-panel>';
         }
 
diff --git a/typo3/sysext/filelist/Classes/Controller/FileListController.php b/typo3/sysext/filelist/Classes/Controller/FileListController.php
index fecad02a247f..45d53d64974e 100644
--- a/typo3/sysext/filelist/Classes/Controller/FileListController.php
+++ b/typo3/sysext/filelist/Classes/Controller/FileListController.php
@@ -74,6 +74,7 @@ class FileListController implements LoggerAwareInterface
     protected string $cmd = '';
     protected string $searchTerm = '';
     protected int $currentPage = 1;
+    protected bool $allowClipboard = true;
 
     protected ?Folder $folderObject = null;
     protected ?DuplicationBehavior $overwriteExistingFiles = null;
@@ -290,8 +291,12 @@ class FileListController implements LoggerAwareInterface
         // Set predefined value for Clipboard:
         if (($userTsConfig['options.']['file_list.']['enableClipBoard'] ?? '') === 'activated') {
             $this->moduleData->set('clipBoard', true);
+            $this->allowClipboard = false;
+        } elseif (($userTsConfig['options.']['file_list.']['enableClipBoard'] ?? '') === 'selectable') {
+            $this->allowClipboard = true;
         } elseif (($userTsConfig['options.']['file_list.']['enableClipBoard'] ?? '') === 'deactivated') {
             $this->moduleData->set('clipBoard', false);
+            $this->allowClipboard = false;
         }
     }
 
@@ -450,9 +455,10 @@ class FileListController implements LoggerAwareInterface
     {
         $lang = $this->getLanguageService();
         $userTsConfig = $this->getBackendUser()->getTSConfig();
+        $enableClipBoard = ($userTsConfig['options.']['file_list.']['enableClipBoard'] ?? '');
 
         $this->view->assign('enableClipBoard', [
-            'enabled' => ($userTsConfig['options.']['file_list.']['enableClipBoard'] ?? '') === 'selectable',
+            'enabled' => $enableClipBoard === 'activated' || $enableClipBoard === 'selectable',
             'label' => htmlspecialchars($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:clipBoard')),
             'mode' => $this->filelist->clipObj->current,
         ]);
@@ -493,11 +499,13 @@ class FileListController implements LoggerAwareInterface
                 ->setLabel($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.showThumbnails'))
                 ->setIcon($this->iconFactory->getIcon('actions-image'));
         }
-        $viewModeItems[] = GeneralUtility::makeInstance(DropDownToggle::class)
-            ->setActive((bool)$this->moduleData->get('clipBoard'))
-            ->setHref($this->filelist->createModuleUri(['clipBoard' => $this->moduleData->get('clipBoard') ? 0 : 1]))
-            ->setLabel($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.showClipboard'))
-            ->setIcon($this->iconFactory->getIcon('actions-clipboard'));
+        if ($this->allowClipboard) {
+            $viewModeItems[] = GeneralUtility::makeInstance(DropDownToggle::class)
+                ->setActive((bool)$this->moduleData->get('clipBoard'))
+                ->setHref($this->filelist->createModuleUri(['clipBoard' => $this->moduleData->get('clipBoard') ? 0 : 1]))
+                ->setLabel($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.view.showClipboard'))
+                ->setIcon($this->iconFactory->getIcon('actions-clipboard'));
+        }
         if (($this->getBackendUser()->getTSConfig()['options.']['file_list.']['displayColumnSelector'] ?? true)
             && $this->moduleData->get('viewMode') === ViewMode::LIST->value) {
             $viewModeItems[] = GeneralUtility::makeInstance(DropDownDivider::class);
-- 
GitLab