1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
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
|
|
|
/* |
19
|
|
|
* Inspired by and partially taken from the Neos.Form package (www.neos.io) |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace TYPO3\CMS\Form\Domain\Finishers; |
23
|
|
|
|
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
25
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext; |
26
|
|
|
use TYPO3\CMS\Extbase\Mvc\Request; |
27
|
|
|
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The context that is passed to each finisher when executed. |
31
|
|
|
* It acts like an EventObject that is able to stop propagation. |
32
|
|
|
* |
33
|
|
|
* Scope: frontend |
34
|
|
|
* **This class is NOT meant to be sub classed by developers.** |
35
|
|
|
* @internal |
36
|
|
|
*/ |
37
|
|
|
class FinisherContext |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* If TRUE further finishers won't be invoked |
42
|
|
|
* |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
protected $cancelled = false; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* A reference to the Form Runtime that the finisher belongs to |
49
|
|
|
* |
50
|
|
|
* @var \TYPO3\CMS\Form\Domain\Runtime\FormRuntime |
51
|
|
|
*/ |
52
|
|
|
protected $formRuntime; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The assigned controller context which might be needed by the finisher. |
56
|
|
|
* |
57
|
|
|
* @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext |
58
|
|
|
*/ |
59
|
|
|
protected $controllerContext; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The assigned controller context which might be needed by the finisher. |
63
|
|
|
* |
64
|
|
|
* @var FinisherVariableProvider |
65
|
|
|
*/ |
66
|
|
|
protected $finisherVariableProvider; |
67
|
|
|
|
68
|
|
|
private Request $request; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param FormRuntime $formRuntime |
72
|
|
|
* @param ControllerContext $controllerContext |
73
|
|
|
* @param Request $request |
74
|
|
|
* @internal |
75
|
|
|
*/ |
76
|
|
|
public function __construct(FormRuntime $formRuntime, ControllerContext $controllerContext, Request $request) |
77
|
|
|
{ |
78
|
|
|
$this->formRuntime = $formRuntime; |
79
|
|
|
$this->controllerContext = $controllerContext; |
80
|
|
|
$this->request = $request; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Sets up the FinisherVariableProvider |
85
|
|
|
*/ |
86
|
|
|
public function initializeObject() |
87
|
|
|
{ |
88
|
|
|
$this->finisherVariableProvider = GeneralUtility::makeInstance(FinisherVariableProvider::class); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Cancels the finisher invocation after the current finisher |
93
|
|
|
*/ |
94
|
|
|
public function cancel() |
95
|
|
|
{ |
96
|
|
|
$this->cancelled = true; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* TRUE if no further finishers should be invoked. Defaults to FALSE |
101
|
|
|
* |
102
|
|
|
* @return bool |
103
|
|
|
* @internal |
104
|
|
|
*/ |
105
|
|
|
public function isCancelled(): bool |
106
|
|
|
{ |
107
|
|
|
return $this->cancelled; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The Form Runtime that is associated with the current finisher |
112
|
|
|
* |
113
|
|
|
* @return FormRuntime |
114
|
|
|
*/ |
115
|
|
|
public function getFormRuntime(): FormRuntime |
116
|
|
|
{ |
117
|
|
|
return $this->formRuntime; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* The values of the submitted form (after validation and property mapping) |
122
|
|
|
* |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
public function getFormValues(): array |
126
|
|
|
{ |
127
|
|
|
return $this->formRuntime->getFormState()->getFormValues(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return ControllerContext |
132
|
|
|
* @deprecated since v11, will be removed in v12 |
133
|
|
|
*/ |
134
|
|
|
public function getControllerContext(): ControllerContext |
135
|
|
|
{ |
136
|
|
|
return $this->controllerContext; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return FinisherVariableProvider |
141
|
|
|
*/ |
142
|
|
|
public function getFinisherVariableProvider(): FinisherVariableProvider |
143
|
|
|
{ |
144
|
|
|
return $this->finisherVariableProvider; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getRequest(): Request |
148
|
|
|
{ |
149
|
|
|
return $this->request; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|