[FEATURE] Make thumbnail size in file list configurable 06/51306/7
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Fri, 13 Jan 2017 14:18:44 +0000 (15:18 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 6 Oct 2017 10:21:52 +0000 (12:21 +0200)
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>
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Feature-73357-MakeThumbnailSizeInFileBrowserConfigurable.rst [new file with mode: 0644]
typo3/sysext/filelist/Classes/Configuration/ThumbnailConfiguration.php [new file with mode: 0644]
typo3/sysext/filelist/Classes/Controller/FileListController.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html
typo3/sysext/recordlist/Classes/Browser/FileBrowser.php

index 4f5ee07..e889afe 100644 (file)
@@ -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 (file)
index 0000000..c0a806b
--- /dev/null
@@ -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 (file)
index 0000000..88441b0
--- /dev/null
@@ -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;
+    }
+}
index a97669c..3956199 100644 (file)
@@ -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'));
index 207bd6b..a07af92 100644 (file)
@@ -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;
 
 /**
@@ -267,6 +268,11 @@ class FileList
     protected $fileListController;
 
     /**
+     * @var ThumbnailConfiguration
+     */
+    protected $thumbnailConfiguration;
+
+    /**
      * Construct
      *
      * @param FileListController $fileListController
@@ -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 . '" ' .
index 48531d6..cc2cce9 100644 (file)
@@ -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">
index c93b610..77437ec 100644 (file)
@@ -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;
 
@@ -67,6 +68,11 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
     protected $fileRepository;
 
     /**
+     * @var array
+     */
+    protected $thumbnailConfiguration = [];
+
+    /**
      * Loads additional JavaScript
      */
     protected function initialize()
@@ -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 = [