|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* 2017 Romain CANON <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
7
|
|
|
* under the terms of the GNU General Public License, either |
|
8
|
|
|
* version 3 of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, see: |
|
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Romm\Formz\Form\Definition\Field\Validation; |
|
15
|
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait; |
|
17
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\ArrayConversionTrait; |
|
18
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait; |
|
19
|
|
|
use Romm\Formz\Configuration\AbstractFormzConfiguration; |
|
20
|
|
|
use Romm\Formz\Form\Definition\Field\Activation\ActivationInterface; |
|
21
|
|
|
use Romm\Formz\Form\Definition\Field\Activation\ActivationUsageInterface; |
|
22
|
|
|
use Romm\Formz\Form\Definition\Field\Activation\EmptyActivation; |
|
23
|
|
|
use Romm\Formz\Form\Definition\Field\Field; |
|
24
|
|
|
|
|
25
|
|
|
class Validation extends AbstractFormzConfiguration implements ActivationUsageInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use StoreArrayIndexTrait; |
|
28
|
|
|
use ArrayConversionTrait; |
|
29
|
|
|
use ParentsTrait; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
* @validate NotEmpty |
|
34
|
|
|
* @validate Romm.ConfigurationObject:ClassImplements(interface=TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface) |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $className; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
* @validate Number |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $priority; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $options = []; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var \Romm\Formz\Form\Definition\Field\Validation\Message[] |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $messages = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var \Romm\Formz\Form\Definition\Field\Activation\ActivationInterface |
|
56
|
|
|
* @mixedTypesResolver \Romm\Formz\Form\Definition\Field\Activation\ActivationResolver |
|
57
|
|
|
* @validate Romm.Formz:Internal\ConditionIsValid |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $activation; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var bool |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $useAjax = false; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Name of the validation. By default, it is the key of this instance in the |
|
68
|
|
|
* array containing all the validation for the parent field. |
|
69
|
|
|
* |
|
70
|
|
|
* @var string |
|
71
|
|
|
*/ |
|
72
|
|
|
private $name; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Constructor. |
|
76
|
|
|
*/ |
|
77
|
|
|
public function __construct() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->activation = EmptyActivation::get(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getClassName() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->className; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $className |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setClassName($className) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->className = $className; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getPriority() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->priority; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param string $priority |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setPriority($priority) |
|
110
|
|
|
{ |
|
111
|
|
|
$this->priority = $priority; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return array |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getOptions() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->options; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param array $options |
|
124
|
|
|
*/ |
|
125
|
|
|
public function setOptions(array $options) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->options = $options; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return Message[] |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getMessages() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->messages; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param Message[] $messages |
|
140
|
|
|
*/ |
|
141
|
|
|
public function setMessages(array $messages) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->messages = $messages; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return ActivationInterface |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getActivation() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->activation; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return bool |
|
156
|
|
|
*/ |
|
157
|
|
|
public function hasActivation() |
|
158
|
|
|
{ |
|
159
|
|
|
return !($this->activation instanceof EmptyActivation); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @param ActivationInterface $activation |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setActivation(ActivationInterface $activation) |
|
166
|
|
|
{ |
|
167
|
|
|
$activation->setRootObject($this); |
|
168
|
|
|
|
|
169
|
|
|
$this->activation = $activation; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getName() |
|
176
|
|
|
{ |
|
177
|
|
|
if (null === $this->name) { |
|
178
|
|
|
$this->name = $this->getArrayIndex(); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
return $this->name; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param string $name |
|
186
|
|
|
*/ |
|
187
|
|
|
public function setName($name) |
|
188
|
|
|
{ |
|
189
|
|
|
$this->name = $name; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @return bool |
|
194
|
|
|
*/ |
|
195
|
|
|
public function doesUseAjax() |
|
196
|
|
|
{ |
|
197
|
|
|
return (bool)$this->useAjax; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param bool $flag |
|
202
|
|
|
*/ |
|
203
|
|
|
public function activateAjaxUsage($flag = true) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->useAjax = (bool)$flag; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return Field |
|
210
|
|
|
*/ |
|
211
|
|
|
public function getParentField() |
|
212
|
|
|
{ |
|
213
|
|
|
/** @var Field $field */ |
|
214
|
|
|
$field = $this->getFirstParent(Field::class); |
|
215
|
|
|
|
|
216
|
|
|
return $field; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|