DeleteFileViewHelper.php 2.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?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\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21
22
23
24

/**
 * Class DeleteFileViewHelper
 */
25
class DeleteFileViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
26
{
27
28
29
30
31
32
33
34
35
36
    /**
     * Initialize arguments
     */
    public function initializeArguments()
    {
        parent::initializeArguments();
        $this->registerArgument('file', \TYPO3\CMS\Core\Resource\AbstractFile::class, '', true);
        $this->registerArgument('returnUrl', 'string', '', false, '');
    }

37
38
39
40
41
    /**
     * Renders a link to delete the file
     *
     * @return string
     */
42
    public function render()
43
44
    {
        return static::renderStatic(
45
            $this->arguments,
46
47
48
49
            $this->buildRenderChildrenClosure(),
            $this->renderingContext
        );
    }
50

51
52
53
54
55
56
57
58
59
60
61
62
63
    /**
     * Renders a link to delete the file
     *
     * @param array $arguments
     * @param Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     *
     * @return string
     */
    public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
    {
        $veriCode = '&vC=';
        if ($GLOBALS['BE_USER'] instanceof \TYPO3\CMS\Core\Authentication\BackendUserAuthentication) {
64
            $veriCode .= $GLOBALS['BE_USER']->veriCode();
65
        }
66

67
68
69
        if (empty($arguments['returnUrl'])) {
            $arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
        }
70

71
72
        /** @var \TYPO3\CMS\Core\Resource\AbstractFile $file */
        $file = $arguments['file'];
73

74
75
76
77
78
79
80
81
82
83
        $params = [
            'file' => [
                'delete' => [
                    0 => [
                        'data' => $file->getCombinedIdentifier()
                    ]
                ]
            ],
            'redirect' => $arguments['returnUrl']
        ];
84

85
86
        return BackendUtility::getModuleUrl('tce_file', $params) . $veriCode;
    }
87
}