‪TYPO3CMS  10.4
CopyCutFileViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Closure;
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
29 class ‪CopyCutFileViewHelper extends AbstractViewHelper
30 {
31  use CompileWithRenderStatic;
32 
36  public function ‪initializeArguments()
37  {
38  $this->registerArgument('file', AbstractFile::class, '', true);
39  $this->registerArgument('copyOrCut', 'string', '', false, 'copy');
40  }
41 
52  public static function ‪renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
53  {
54  if ($arguments['copyOrCut'] !== 'cut' && $arguments['copyOrCut'] !== 'copy') {
55  throw new \InvalidArgumentException('Argument "copyOrCut" must be either "copy" or "cut"', 1540548015);
56  }
57 
59  $file = $arguments['file'];
60 
62  $clipboard = GeneralUtility::makeInstance(Clipboard::class);
63  $clipboard->initializeClipboard();
64 
65  $fullIdentifier = $file->getCombinedIdentifier();
66  $md5 = GeneralUtility::shortMD5($fullIdentifier);
67  $isSel = $clipboard->isSelected('_FILE', $md5);
68 
69  if ($arguments['copyOrCut'] === 'copy') {
70  return $clipboard->selUrlFile($fullIdentifier, true, $isSel === 'copy');
71  }
72  return $clipboard->selUrlFile($fullIdentifier, false, $isSel === 'cut');
73  }
74 }
‪TYPO3\CMS\Filelist\ViewHelpers\Uri\CopyCutFileViewHelper\renderStatic
‪static string renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: CopyCutFileViewHelper.php:51
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:43
‪TYPO3\CMS\Filelist\ViewHelpers\Uri
Definition: CopyCutFileViewHelper.php:16
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:26
‪TYPO3\CMS\Filelist\ViewHelpers\Uri\CopyCutFileViewHelper
Definition: CopyCutFileViewHelper.php:30
‪TYPO3\CMS\Filelist\ViewHelpers\Uri\CopyCutFileViewHelper\initializeArguments
‪initializeArguments()
Definition: CopyCutFileViewHelper.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46