From b5652c7be787b84c840e1fe8d5b489b6dd098922 Mon Sep 17 00:00:00 2001
From: Alexander Schnitzler <git@alexanderschnitzler.de>
Date: Fri, 13 Jan 2017 15:18:44 +0100
Subject: [PATCH] [FEATURE] Make thumbnail size in file list configurable

The size of thumbnails of the file list is hard coded to
64x64 px which might not be optimal in some cases. Thus,
the size should be configurable via UserTS.

Releases: master
Resolves: #73357
Change-Id: Ibd3bd43e55231212a410ee56b375e9be5d4354d2
Reviewed-on: https://review.typo3.org/51306
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Markus Sommer <markus.sommer@typo3.org>
Tested-by: Markus Sommer <markus.sommer@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Configuration/DefaultConfiguration.php    |  4 ++
 ...ThumbnailSizeInFileBrowserConfigurable.rst | 26 +++++++
 .../Configuration/ThumbnailConfiguration.php  | 68 +++++++++++++++++++
 .../Classes/Controller/FileListController.php |  7 ++
 typo3/sysext/filelist/Classes/FileList.php    | 15 +++-
 .../Private/Templates/FileList/Search.html    |  2 +-
 .../Classes/Browser/FileBrowser.php           | 20 +++++-
 7 files changed, 139 insertions(+), 3 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-73357-MakeThumbnailSizeInFileBrowserConfigurable.rst
 create mode 100644 typo3/sysext/filelist/Classes/Configuration/ThumbnailConfiguration.php

diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php
index 4f5ee07db892..e889afebc7bc 100644
--- a/typo3/sysext/core/Configuration/DefaultConfiguration.php
+++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php
@@ -859,6 +859,10 @@ return [
 			options.file_list.enableDisplayBigControlPanel=selectable
 			options.file_list.enableDisplayThumbnails=selectable
 			options.file_list.enableClipBoard=selectable
+			options.file_list.thumbnail {
+				width = 64
+				height = 64
+			}
 			options.pageTree {
 				doktypesToShowInNewPageDragArea = 1,6,4,7,3,254,255,199
 			}
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-73357-MakeThumbnailSizeInFileBrowserConfigurable.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-73357-MakeThumbnailSizeInFileBrowserConfigurable.rst
new file mode 100644
index 000000000000..c0a806b03fc4
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-73357-MakeThumbnailSizeInFileBrowserConfigurable.rst
@@ -0,0 +1,26 @@
+.. include:: ../../Includes.txt
+
+==================================================================
+Feature: #73357 - Make thumbnail size in file browser configurable
+==================================================================
+
+See :issue:`73357`
+
+Description
+===========
+
+The default size of thumbnails in the file list is 64x64. These values can now be configured with UserTSConfig.
+
+Example:
+
+.. code-block:: typoscript
+   options.file_list.thumbnail.width = 256
+   options.file_list.thumbnail.height = 256
+
+
+Impact
+======
+
+All preview images in the file list will be rendered in the configured thumbnail size.
+
+.. index:: Backend, TSConfig
diff --git a/typo3/sysext/filelist/Classes/Configuration/ThumbnailConfiguration.php b/typo3/sysext/filelist/Classes/Configuration/ThumbnailConfiguration.php
new file mode 100644
index 000000000000..88441b02468c
--- /dev/null
+++ b/typo3/sysext/filelist/Classes/Configuration/ThumbnailConfiguration.php
@@ -0,0 +1,68 @@
+<?php
+declare(strict_types=1);
+
+namespace TYPO3\CMS\Filelist\Configuration;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\SingletonInterface;
+use TYPO3\CMS\Core\Utility\MathUtility;
+
+/**
+ * Class TYPO3\CMS\Filelist\Configuration\ThumbnailConfiguration
+ */
+class ThumbnailConfiguration implements SingletonInterface
+{
+    /**
+     * @var int
+     */
+    protected $width = 64;
+
+    /**
+     * @var int
+     */
+    protected $height = 64;
+
+    public function __construct()
+    {
+        $modTSconfig = BackendUtility::getModTSconfig(0, 'options.file_list');
+        if (isset($modTSconfig['properties']['thumbnail.']['width'])
+            && MathUtility::canBeInterpretedAsInteger($modTSconfig['properties']['thumbnail.']['width'])
+        ) {
+            $this->width = (int)$modTSconfig['properties']['thumbnail.']['width'];
+        }
+        if (isset($modTSconfig['properties']['thumbnail.']['height'])
+            && MathUtility::canBeInterpretedAsInteger($modTSconfig['properties']['thumbnail.']['height'])
+        ) {
+            $this->height = (int)$modTSconfig['properties']['thumbnail.']['height'];
+        }
+    }
+
+    /**
+     * @return int
+     */
+    public function getWidth(): int
+    {
+        return $this->width;
+    }
+
+    /**
+     * @return int
+     */
+    public function getHeight(): int
+    {
+        return $this->height;
+    }
+}
diff --git a/typo3/sysext/filelist/Classes/Controller/FileListController.php b/typo3/sysext/filelist/Classes/Controller/FileListController.php
index a97669c494cb..3956199ad97f 100644
--- a/typo3/sysext/filelist/Classes/Controller/FileListController.php
+++ b/typo3/sysext/filelist/Classes/Controller/FileListController.php
@@ -34,6 +34,7 @@ use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+use TYPO3\CMS\Filelist\Configuration\ThumbnailConfiguration;
 use TYPO3\CMS\Filelist\FileList;
 
 /**
@@ -519,6 +520,12 @@ class FileListController extends ActionController
         $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileList');
 
+        $thumbnailConfiguration = GeneralUtility::makeInstance(ThumbnailConfiguration::class);
+        $this->view->assign('thumbnail', [
+            'width' => $thumbnailConfiguration->getWidth(),
+            'height' => $thumbnailConfiguration->getHeight(),
+        ]);
+
         $this->view->assign('searchWord', $searchWord);
         $this->view->assign('files', $fileFacades);
         $this->view->assign('deleteUrl', BackendUtility::getModuleUrl('tce_file'));
diff --git a/typo3/sysext/filelist/Classes/FileList.php b/typo3/sysext/filelist/Classes/FileList.php
index 207bd6b3be77..a07af92a93b3 100644
--- a/typo3/sysext/filelist/Classes/FileList.php
+++ b/typo3/sysext/filelist/Classes/FileList.php
@@ -36,6 +36,7 @@ use TYPO3\CMS\Core\Resource\Utility\ListUtility;
 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Filelist\Configuration\ThumbnailConfiguration;
 use TYPO3\CMS\Filelist\Controller\FileListController;
 
 /**
@@ -266,6 +267,11 @@ class FileList
      */
     protected $fileListController;
 
+    /**
+     * @var ThumbnailConfiguration
+     */
+    protected $thumbnailConfiguration;
+
     /**
      * Construct
      *
@@ -281,6 +287,7 @@ class FileList
         $this->determineScriptUrl();
         $this->fileListController = $fileListController;
         $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+        $this->thumbnailConfiguration = GeneralUtility::makeInstance(ThumbnailConfiguration::class);
 
         $modTSconfig = BackendUtility::getModTSconfig(0, 'options.file_list');
         if (!empty($modTSconfig['properties']['filesPerPage'])) {
@@ -1099,7 +1106,13 @@ class FileList
                                 . '</span>';
                             // Thumbnails?
                         } elseif ($this->thumbs && ($this->isImage($ext) || $this->isMediaFile($ext))) {
-                            $processedFile = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, []);
+                            $processedFile = $fileObject->process(
+                                ProcessedFile::CONTEXT_IMAGEPREVIEW,
+                                [
+                                    'width' => $this->thumbnailConfiguration->getWidth(),
+                                    'height' => $this->thumbnailConfiguration->getHeight()
+                                ]
+                            );
                             if ($processedFile) {
                                 $thumbUrl = $processedFile->getPublicUrl(true);
                                 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" ' .
diff --git a/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html b/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html
index 48531d650325..cc2cce93dbdc 100644
--- a/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html
+++ b/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html
@@ -54,7 +54,7 @@
 							</f:if>
 							<f:if condition="{file.isImage}">
 								<br>
-								<f:image image="{file.resource}" maxWidth="64" maxHeight="43" />
+								<f:image image="{file.resource}" maxWidth="{thumbnail.width}" maxHeight="{thumbnail.height}" />
 							</f:if>
 						</td>
 						<td class="col-control nowrap">
diff --git a/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php b/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
index c93b61011ba7..77437ecbfe1c 100644
--- a/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
+++ b/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
@@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Resource\ProcessedFile;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Recordlist\Tree\View\LinkParameterProviderInterface;
 use TYPO3\CMS\Recordlist\View\FolderUtilityRenderer;
 
@@ -66,6 +67,11 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
      */
     protected $fileRepository;
 
+    /**
+     * @var array
+     */
+    protected $thumbnailConfiguration = [];
+
     /**
      * Loads additional JavaScript
      */
@@ -74,6 +80,18 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
         parent::initialize();
         $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/BrowseFiles');
         $this->fileRepository = GeneralUtility::makeInstance(FileRepository::class);
+
+        $modTSconfig = BackendUtility::getModTSconfig(0, 'options.file_list');
+        if (isset($modTSconfig['properties']['thumbnail.']['width'])
+            && MathUtility::canBeInterpretedAsInteger($modTSconfig['properties']['thumbnail.']['width'])
+        ) {
+            $this->thumbnailConfiguration['width'] = (int)$modTSconfig['properties']['thumbnail.']['width'];
+        }
+        if (isset($modTSconfig['properties']['thumbnail.']['height'])
+            && MathUtility::canBeInterpretedAsInteger($modTSconfig['properties']['thumbnail.']['height'])
+        ) {
+            $this->thumbnailConfiguration['height'] = (int)$modTSconfig['properties']['thumbnail.']['height'];
+        }
     }
 
     /**
@@ -270,7 +288,7 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
             if (!$noThumbs && GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] . ',' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']), strtolower($fileExtension))) {
                 $processedFile = $fileObject->process(
                     ProcessedFile::CONTEXT_IMAGEPREVIEW,
-                    ['width' => 64, 'height' => 64]
+                    $this->thumbnailConfiguration
                 );
                 $imageUrl = $processedFile->getPublicUrl(true);
                 $imgInfo = [
-- 
GitLab