[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[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\Core\Utility\GeneralUtility;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
21
22 /**
23 * Class DeleteFileViewHelper
24 */
25 class DeleteFileViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
26 {
27 use CompileWithRenderStatic;
28
29 /**
30 * Initialize arguments
31 */
32 public function initializeArguments()
33 {
34 parent::initializeArguments();
35 $this->registerArgument('file', \TYPO3\CMS\Core\Resource\AbstractFile::class, '', true);
36 $this->registerArgument('returnUrl', 'string', '', false, '');
37 }
38
39 /**
40 * Renders a link to delete the file
41 *
42 * @param array $arguments
43 * @param Closure $renderChildrenClosure
44 * @param RenderingContextInterface $renderingContext
45 *
46 * @return string
47 */
48 public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
49 {
50 if (empty($arguments['returnUrl'])) {
51 $arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
52 }
53
54 /** @var \TYPO3\CMS\Core\Resource\AbstractFile $file */
55 $file = $arguments['file'];
56
57 $params = [
58 'file' => [
59 'delete' => [
60 0 => [
61 'data' => $file->getCombinedIdentifier()
62 ]
63 ]
64 ],
65 'redirect' => $arguments['returnUrl']
66 ];
67 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
68 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
69 return (string)$uriBuilder->buildUriFromRoute('tce_file', $params);
70 }
71 }