Skip to content

Commit

Permalink
[BUGFIX] Add missing copy and cut button in file list search result
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gmartino27 authored and bmack committed Oct 28, 2018
1 parent 4c9699a commit 0430307
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
48 changes: 48 additions & 0 deletions typo3/sysext/filelist/Classes/FileFacade.php
Expand Up @@ -14,6 +14,7 @@
* 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;
Expand Down Expand Up @@ -228,6 +229,32 @@ public function getIsRenamable()
return false;
}

/**
* @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
*/
Expand All @@ -241,6 +268,27 @@ public function getIsDeletable()
return false;
}

/**
* @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
*/
Expand Down
@@ -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');
}
}
Expand Up @@ -143,6 +143,42 @@ <h1><f:translate id="search">Search</f:translate>: "{searchWord}"</h1>
<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"
Expand Down
20 changes: 20 additions & 0 deletions typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js
Expand Up @@ -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;
});

});

/**
Expand Down

0 comments on commit 0430307

Please sign in to comment.