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\Configuration\Form\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\Configuration\Form\Field\Activation\ActivationInterface; |
21
|
|
|
use Romm\Formz\Configuration\Form\Field\Activation\ActivationUsageInterface; |
22
|
|
|
use Romm\Formz\Configuration\Form\Field\Activation\EmptyActivation; |
23
|
|
|
use Romm\Formz\Configuration\Form\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\Configuration\Form\Field\Validation\Message[] |
51
|
|
|
*/ |
52
|
|
|
protected $messages = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var ActivationInterface |
56
|
|
|
* @mixedTypesResolver \Romm\Formz\Configuration\Form\Condition\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
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
|
public function getOptions() |
110
|
|
|
{ |
111
|
|
|
return $this->options; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $optionName |
116
|
|
|
* @return null|mixed |
117
|
|
|
*/ |
118
|
|
|
public function getOption($optionName) |
119
|
|
|
{ |
120
|
|
|
return (null !== $optionName && true === isset($this->options[$optionName])) |
121
|
|
|
? $this->options[$optionName] |
122
|
|
|
: null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return Message[] |
127
|
|
|
*/ |
128
|
|
|
public function getMessages() |
129
|
|
|
{ |
130
|
|
|
return $this->messages; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param Message[] $messages |
135
|
|
|
*/ |
136
|
|
|
public function setMessages(array $messages) |
137
|
|
|
{ |
138
|
|
|
$this->messages = $messages; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return ActivationInterface |
143
|
|
|
*/ |
144
|
|
|
public function getActivation() |
145
|
|
|
{ |
146
|
|
|
return $this->activation; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return bool |
151
|
|
|
*/ |
152
|
|
|
public function hasActivation() |
153
|
|
|
{ |
154
|
|
|
return !($this->activation instanceof EmptyActivation); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param ActivationInterface $activation |
159
|
|
|
*/ |
160
|
|
|
public function setActivation(ActivationInterface $activation) |
161
|
|
|
{ |
162
|
|
|
$activation->setRootObject($this); |
163
|
|
|
|
164
|
|
|
$this->activation = $activation; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getName() |
171
|
|
|
{ |
172
|
|
|
if (null === $this->name) { |
173
|
|
|
$this->name = $this->getArrayIndex(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return $this->name; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $name |
181
|
|
|
*/ |
182
|
|
|
public function setName($name) |
183
|
|
|
{ |
184
|
|
|
$this->name = $name; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return bool |
189
|
|
|
*/ |
190
|
|
|
public function doesUseAjax() |
191
|
|
|
{ |
192
|
|
|
return (bool)$this->useAjax; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param bool $flag |
197
|
|
|
*/ |
198
|
|
|
public function activateAjaxUsage($flag = true) |
199
|
|
|
{ |
200
|
|
|
$this->useAjax = (bool)$flag; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return Field |
205
|
|
|
*/ |
206
|
|
|
public function getParentField() |
207
|
|
|
{ |
208
|
|
|
return $this->getFirstParent(Field::class); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|