[FEATURE] EXT:form - integrate new form framework
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Finishers / DeleteUploadsFinisher.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Domain\Finishers;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Extbase\Domain\Model\FileReference;
19 use TYPO3\CMS\Form\Domain\Model\FormElements\FileUpload;
20
21 /**
22 * This finisher remove the submited files.
23 * Use this e.g after the email finisher if you dont want
24 * to keep the files online.
25 *
26 * Scope: frontend
27 */
28 class DeleteUploadsFinisher extends AbstractFinisher
29 {
30
31 /**
32 * Executes this finisher
33 * @see AbstractFinisher::execute()
34 *
35 * @return void
36 */
37 protected function executeInternal()
38 {
39 $formRuntime = $this->finisherContext->getFormRuntime();
40
41 $elements = $formRuntime->getFormDefinition()->getRenderablesRecursively();
42 foreach ($elements as $element) {
43 if (!$element instanceof FileUpload) {
44 continue;
45 }
46 $file = $formRuntime[$element->getIdentifier()];
47 if (!$file) {
48 continue;
49 }
50
51 if ($file instanceof FileReference) {
52 $file = $file->getOriginalResource();
53 }
54 $file->getStorage()->deleteFile($file);
55 }
56 }
57 }