[BUGFIX] Pass record info when determining defaultUploadFolder in FileBrowser 75/58775/5
authorFrans Saris <franssaris@gmail.com>
Fri, 31 Aug 2018 08:21:13 +0000 (10:21 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 29 Oct 2018 11:02:21 +0000 (12:02 +0100)
The fileBrowser now passes the related pid, table and field to
getDefaultUploadFolder().

Resolves: #86053
Releases: master, 8.7
Change-Id: I954753ee84b4107b37ba45cbd08917f4c4be17d9
Reviewed-on: https://review.typo3.org/58775
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/recordlist/Classes/Browser/AbstractElementBrowser.php
typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
typo3/sysext/recordlist/Tests/Unit/Browser/FileBrowserTest.php [new file with mode: 0644]

index 5bd0621..9c83b5d 100644 (file)
@@ -58,13 +58,12 @@ abstract class AbstractElementBrowser
      * opens - thus allows us to make references back to the main window in which the form is.
      * Example value: "data[pages][39][bodytext]|||tt_content|"
      * or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|"
-     *
      * Values:
      * 0: form field name reference, eg. "data[tt_content][123][image]"
      * 1: htmlArea RTE parameters: editorNo:contentTypo3Language
      * 2: RTE config parameters: RTEtsConfigParams
      * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai"
-     * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data[79][tt_address][1][<field>][<foreign_table>]"
+     * 4: IRRE uniqueness: target level object-id to perform actions/checks on, eg. "data-4-pages-4-nav_icon-sys_file_reference" ("data-<uid>-<table>-<pid>-<field>-<foreign_table>")
      * 5: IRRE uniqueness: name of function in opener window that checks if element is already used, eg. "inline.checkUniqueElement"
      * 6: IRRE uniqueness: name of function in opener window that performs some additional(!) action, eg. "inline.setUniqueElement"
      * 7: IRRE uniqueness: name of function in opener window that performs action instead of using addElement/insertElement, eg. "inline.importElement"
index 7b9fd74..72485d3 100644 (file)
@@ -149,7 +149,8 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
         // Or get the user's default upload folder
         if (!$this->selectedFolder) {
             try {
-                $this->selectedFolder = $backendUser->getDefaultUploadFolder();
+                list(, $pid, $table, , $field) = explode('-', explode('|', $this->bparams)[4]);
+                $this->selectedFolder = $backendUser->getDefaultUploadFolder($pid, $table, $field);
             } catch (\Exception $e) {
                 // The configured default user folder does not exist
             }
@@ -172,7 +173,8 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
             $_MCONF['name'] = 'file_list';
             $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']);
         }
-        $noThumbs = $noThumbs ?: !$_MOD_SETTINGS['displayThumbs'];
+        $displayThumbs = $_MOD_SETTINGS['displayThumbs'] ?? false;
+        $noThumbs = $noThumbs ?: !$displayThumbs;
         // Create folder tree:
         /** @var ElementBrowserFolderTreeView $folderTree */
         $folderTree = GeneralUtility::makeInstance(ElementBrowserFolderTreeView::class);
diff --git a/typo3/sysext/recordlist/Tests/Unit/Browser/FileBrowserTest.php b/typo3/sysext/recordlist/Tests/Unit/Browser/FileBrowserTest.php
new file mode 100644 (file)
index 0000000..40edb11
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Recordlist\Tests\Unit\Browser;
+
+/*
+ * 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 Prophecy\Argument;
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
+use TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
+use TYPO3\CMS\Recordlist\Browser\FileBrowser;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+class FileBrowserTest extends UnitTestCase
+{
+
+    /**
+     * @test
+     */
+    public function renderGetsUserDefaultUploadFolderForCurrentPageData()
+    {
+        list($documentTemplate, $beUser) = $this->setupProphecies();
+
+        $bparams = '|||gif,png,svg|data-4-pages-4-nav_icon-sys_file_reference|inline.checkUniqueElement||inline.importElement';
+        $fileBrowser = $this->getAccessibleMock(FileBrowser::class, ['initDocumentTemplate'], [], '', false);
+        $fileBrowser->_set('bparams', $bparams);
+        $fileBrowser->_set('doc', $documentTemplate->reveal());
+        $fileBrowser->render();
+
+        $beUser->getTSConfigVal(Argument::cetera())->shouldHaveBeenCalled();
+        $beUser->getDefaultUploadFolder(4, 'pages', 'nav_icon')->shouldHaveBeenCalled();
+    }
+
+    /**
+     * @return array
+     */
+    private function setupProphecies(): array
+    {
+        $browserFolderTreeView = $this->prophesize(ElementBrowserFolderTreeView::class);
+        GeneralUtility::addInstance(ElementBrowserFolderTreeView::class, $browserFolderTreeView->reveal());
+
+        $documentTemplate = $this->prophesize(DocumentTemplate::class);
+        $lang = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $lang->reveal();
+
+        $beUser = $this->prophesize(BackendUserAuthentication::class);
+        $beUser->getFileStorages()->willReturn([]);
+        $beUser->getTSConfigVal(Argument::cetera())->willReturn('');
+        $beUser->getModuleData(Argument::cetera())->willReturn([]);
+        $beUser->getDefaultUploadFolder(Argument::cetera())->willReturn('');
+        $GLOBALS['BE_USER'] = $beUser->reveal();
+        return [$documentTemplate, $beUser];
+    }
+}