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\Condition\Activation\ActivationInterface; |
21
|
|
|
use Romm\Formz\Configuration\Form\Condition\Activation\EmptyActivation; |
22
|
|
|
use Romm\Formz\Configuration\Form\Field\Field; |
23
|
|
|
|
24
|
|
|
class Validation extends AbstractFormzConfiguration |
25
|
|
|
{ |
26
|
|
|
use StoreArrayIndexTrait; |
27
|
|
|
use ArrayConversionTrait; |
28
|
|
|
use ParentsTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* @validate NotEmpty |
33
|
|
|
* @validate Romm.ConfigurationObject:ClassImplements(interface=TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface) |
34
|
|
|
*/ |
35
|
|
|
protected $className; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
* @validate Number |
40
|
|
|
*/ |
41
|
|
|
protected $priority; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $options = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \ArrayObject<Romm\Formz\Configuration\Form\Field\Validation\Message> |
50
|
|
|
*/ |
51
|
|
|
protected $messages = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var \Romm\Formz\Configuration\Form\Condition\Activation\ActivationResolver |
55
|
|
|
* @validate Romm.Formz:Internal\ConditionIsValid |
56
|
|
|
*/ |
57
|
|
|
protected $activation; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
protected $useAjax = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Constructor. |
66
|
|
|
*/ |
67
|
|
|
public function __construct() |
68
|
|
|
{ |
69
|
|
|
$this->activation = EmptyActivation::get(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getClassName() |
76
|
|
|
{ |
77
|
|
|
return $this->className; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return int |
82
|
|
|
*/ |
83
|
|
|
public function getPriority() |
84
|
|
|
{ |
85
|
|
|
return $this->priority; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getOptions() |
92
|
|
|
{ |
93
|
|
|
return $this->options; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $optionName |
98
|
|
|
* @return null|mixed |
99
|
|
|
*/ |
100
|
|
|
public function getOption($optionName) |
101
|
|
|
{ |
102
|
|
|
return (null !== $optionName && true === isset($this->options[$optionName])) |
103
|
|
|
? $this->options[$optionName] |
104
|
|
|
: null; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return Message[] |
109
|
|
|
*/ |
110
|
|
|
public function getMessages() |
111
|
|
|
{ |
112
|
|
|
return $this->messages; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param Message[] $messages |
117
|
|
|
*/ |
118
|
|
|
public function setMessages(array $messages) |
119
|
|
|
{ |
120
|
|
|
$this->messages = $messages; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return ActivationInterface |
125
|
|
|
*/ |
126
|
|
|
public function getActivation() |
127
|
|
|
{ |
128
|
|
|
return $this->activation; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return bool |
133
|
|
|
*/ |
134
|
|
|
public function hasActivation() |
135
|
|
|
{ |
136
|
|
|
return !($this->activation instanceof EmptyActivation); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function getValidationName() |
143
|
|
|
{ |
144
|
|
|
return $this->getArrayIndex(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return bool |
149
|
|
|
*/ |
150
|
|
|
public function doesUseAjax() |
151
|
|
|
{ |
152
|
|
|
return (bool) $this->useAjax; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return Field |
157
|
|
|
*/ |
158
|
|
|
public function getParentField() |
159
|
|
|
{ |
160
|
|
|
return $this->getFirstParent(Field::class); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|