[!!!][TASK] Remove deprecated code from BackendUtility
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / Classes / ViewHelpers / Uri / DeleteFileViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Filelist\ViewHelpers\Uri;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Closure;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
22
23 /**
24 * Class DeleteFileViewHelper
25 */
26 class DeleteFileViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper implements CompilableInterface
27 {
28 /**
29 * Renders a link to delete the file
30 *
31 * @param \TYPO3\CMS\Core\Resource\AbstractFile $file
32 * @param string $returnUrl
33 *
34 * @return string
35 */
36 public function render(\TYPO3\CMS\Core\Resource\AbstractFile $file, $returnUrl = '')
37 {
38 return static::renderStatic(
39 [
40 'file' => $file,
41 'returnUrl' => $returnUrl,
42 ],
43 $this->buildRenderChildrenClosure(),
44 $this->renderingContext
45 );
46 }
47
48 /**
49 * Renders a link to delete the file
50 *
51 * @param array $arguments
52 * @param Closure $renderChildrenClosure
53 * @param RenderingContextInterface $renderingContext
54 *
55 * @return string
56 */
57 public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
58 {
59 $veriCode = '&vC=';
60 if ($GLOBALS['BE_USER'] instanceof \TYPO3\CMS\Core\Authentication\BackendUserAuthentication) {
61 $veriCode .= $GLOBALS['BE_USER']->veriCode();
62 }
63
64 if (empty($arguments['returnUrl'])) {
65 $arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
66 }
67
68 /** @var \TYPO3\CMS\Core\Resource\AbstractFile $file */
69 $file = $arguments['file'];
70
71 $params = [
72 'file' => [
73 'delete' => [
74 0 => [
75 'data' => $file->getCombinedIdentifier()
76 ]
77 ]
78 ],
79 'redirect' => $arguments['returnUrl']
80 ];
81
82 return BackendUtility::getModuleUrl('tce_file', $params) . $veriCode;
83 }
84 }