[BUGFIX] Add missing copy and cut button in file list search result 26/58426/11
authorGianluigi Martino <gmartino27@gmail.com>
Fri, 28 Sep 2018 06:54:40 +0000 (08:54 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 28 Oct 2018 16:15:13 +0000 (17:15 +0100)
It is now possible to copy or cut the file in file list search result.

Resolves: #86414
Releases: master
Change-Id: I60ca052d36efaa45cc348f712b05cac3127cc120
Reviewed-on: https://review.typo3.org/58426
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Felix Althaus <felix.althaus@undkonsorten.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/filelist/Classes/FileFacade.php
typo3/sysext/filelist/Classes/ViewHelpers/Uri/CopyCutFileViewHelper.php [new file with mode: 0644]
typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html
typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js

index 43ea904..14dc293 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Filelist;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Clipboard\Clipboard;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -231,6 +232,32 @@ class FileFacade
     /**
      * @return bool
      */
+    public function isCopyable()
+    {
+        $method = 'checkActionPermission';
+        if (is_callable([$this->resource, $method])) {
+            return call_user_func_array([$this->resource, $method], ['copy']);
+        }
+
+        return false;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isCuttable()
+    {
+        $method = 'checkActionPermission';
+        if (is_callable([$this->resource, $method])) {
+            return call_user_func_array([$this->resource, $method], ['move']);
+        }
+
+        return false;
+    }
+
+    /**
+     * @return bool
+     */
     public function getIsDeletable()
     {
         $method = 'checkActionPermission';
@@ -244,6 +271,27 @@ class FileFacade
     /**
      * @return bool
      */
+    public function isSelected()
+    {
+        $fullIdentifier = $this->getIdentifier();
+        $md5 = GeneralUtility::shortMD5($fullIdentifier);
+
+        /** @var Clipboard $clipboard */
+        $clipboard = GeneralUtility::makeInstance(Clipboard::class);
+        $clipboard->initializeClipboard();
+
+        $isSel = $clipboard->isSelected('_FILE', $md5);
+
+        if ($isSel) {
+            return $isSel;
+        }
+
+        return false;
+    }
+
+    /**
+     * @return bool
+     */
     public function getIsImage()
     {
         return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->getExtension()));
diff --git a/typo3/sysext/filelist/Classes/ViewHelpers/Uri/CopyCutFileViewHelper.php b/typo3/sysext/filelist/Classes/ViewHelpers/Uri/CopyCutFileViewHelper.php
new file mode 100644 (file)
index 0000000..e87fe3e
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+namespace TYPO3\CMS\Filelist\ViewHelpers\Uri;
+
+/*
+ * 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 Closure;
+use TYPO3\CMS\Backend\Clipboard\Clipboard;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
+
+/**
+ * Class EditFileContentViewHelper
+ */
+class CopyCutFileViewHelper extends AbstractViewHelper
+{
+    use CompileWithRenderStatic;
+
+    /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        $this->registerArgument('file', \TYPO3\CMS\Core\Resource\AbstractFile::class, '', true);
+        $this->registerArgument('copyOrCut', 'string', '', false, 'copy');
+    }
+
+    /**
+     * Renders a link to copy a file
+     *
+     * @param array $arguments
+     * @param Closure $renderChildrenClosure
+     * @param RenderingContextInterface $renderingContext
+     *
+     * @return string
+     * @throws \InvalidArgumentException
+     */
+    public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
+    {
+        if ($arguments['copyOrCut'] !== 'cut' && $arguments['copyOrCut'] !== 'copy') {
+            throw new \InvalidArgumentException('Argument "copyOrCut" must be either "copy" or "cut"', 1540548015);
+        }
+
+        /** @var \TYPO3\CMS\Core\Resource\AbstractFile $file */
+        $file = $arguments['file'];
+
+        /** @var Clipboard $clipboard */
+        $clipboard = GeneralUtility::makeInstance(Clipboard::class);
+        $clipboard->initializeClipboard();
+
+        $fullIdentifier = $file->getCombinedIdentifier();
+        $md5 = GeneralUtility::shortMD5($fullIdentifier);
+        $isSel = $clipboard->isSelected('_FILE', $md5);
+
+        if ($arguments['copyOrCut'] === 'copy') {
+            return $clipboard->selUrlFile($fullIdentifier, true, $isSel === 'copy');
+        }
+        return $clipboard->selUrlFile($fullIdentifier, false, $isSel === 'cut');
+    }
+}
index d110803..1aa4b43 100644 (file)
                                                                                <span class="btn btn-default disabled"><core:icon identifier="empty-empty" /></span>
                                                                        </f:else>
                                                                </f:if>
+
+                                                               <f:if condition="{file.copyable}">
+                                                                       <f:then>
+                                                                               <a href="#" class="btn btn-default filelist-file-copy"
+                                                                                  title="{f:translate( key:'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy' )}"
+                                                                                  data-url="{fl:uri.copyCutFile( file:file.resource, copyOrCut: 'copy' )}"
+                                                                                  data-redirect-url="{f:uri.action( action:'search', arguments:{ searchWord:'{searchWord->f:format.htmlentities()}' } )}"
+                                                                               >
+                                                                                       <f:if condition="{file.selected} == 'copy'">
+                                                                                               <f:then><core:icon identifier="actions-edit-copy-release" /></f:then>
+                                                                                               <f:else><core:icon identifier="actions-edit-copy" /></f:else>
+                                                                                       </f:if>
+                                                                               </a>
+                                                                       </f:then>
+                                                                       <f:else>
+                                                                               <span class="btn btn-default disabled"><core:icon identifier="empty-empty" /></span>
+                                                                       </f:else>
+                                                               </f:if>
+                                                               <f:if condition="{file.cuttable}">
+                                                                       <f:then>
+                                                                               <a href="#" class="btn btn-default filelist-file-cut"
+                                                                                  title="{f:translate( key:'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cut' )}"
+                                                                                  data-url="{fl:uri.copyCutFile( file:file.resource, copyOrCut: 'cut' )}"
+                                                                               >
+                                                                                       <f:if condition="{file.selected} == 'cut'">
+                                                                                               <f:then><core:icon identifier="actions-edit-cut-release" /></f:then>
+                                                                                               <f:else><core:icon identifier="actions-edit-cut" /></f:else>
+                                                                                       </f:if>
+                                                                               </a>
+                                                                       </f:then>
+                                                                       <f:else>
+                                                                               <span class="btn btn-default disabled"><core:icon identifier="empty-empty" /></span>
+                                                                       </f:else>
+                                                               </f:if>
+
+
                                                                <f:if condition="{file.isDeletable}">
                                                                        <f:then>
                                                                                <a href="#" class="btn btn-default t3js-filelist-delete"
index 4e5323b..122306a 100644 (file)
@@ -67,6 +67,26 @@ define(['jquery', 'TYPO3/CMS/Backend/InfoWindow'], function($, InfoWindow) {
       openFileInfoPopup(identifier);
     });
 
+    $('a.btn.filelist-file-copy').click(function(event) {
+        event.preventDefault();
+
+        var url = $(this).attr('data-url');
+        var redirectUrl = $(this).attr('data-url');
+        if (redirectUrl) {
+            redirectUrl = top.rawurlencode(redirectUrl);
+        } else {
+            redirectUrl = top.rawurlencode(top.list_frame.document.location.pathname + top.list_frame.document.location.search);
+        }
+        top.list_frame.location.href = url + '&redirect=' + redirectUrl;
+    });
+
+    $('a.btn.filelist-file-cut').click(function(event) {
+        event.preventDefault();
+
+        var url = $(this).attr('data-url');
+        top.list_frame.location.href = url;
+    });
+
   });
 
   /**