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; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait; |
17
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait; |
18
|
|
|
use Romm\Formz\Configuration\AbstractFormzConfiguration; |
19
|
|
|
use Romm\Formz\Configuration\Form\Condition\Activation\ActivationInterface; |
20
|
|
|
use Romm\Formz\Configuration\Form\Condition\Activation\ActivationUsageInterface; |
21
|
|
|
use Romm\Formz\Configuration\Form\Condition\Activation\EmptyActivation; |
22
|
|
|
use Romm\Formz\Configuration\Form\Field\Behaviour\Behaviour; |
23
|
|
|
use Romm\Formz\Configuration\Form\Field\Settings\FieldSettings; |
24
|
|
|
use Romm\Formz\Configuration\Form\Field\Validation\Validation; |
25
|
|
|
use Romm\Formz\Configuration\Form\Form; |
26
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
27
|
|
|
|
28
|
|
|
class Field extends AbstractFormzConfiguration implements ActivationUsageInterface |
29
|
|
|
{ |
30
|
|
|
use StoreArrayIndexTrait; |
31
|
|
|
use ParentsTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var \ArrayObject<Romm\Formz\Configuration\Form\Field\Validation\Validation> |
35
|
|
|
*/ |
36
|
|
|
protected $validation = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \ArrayObject<Romm\Formz\Configuration\Form\Field\Behaviour\Behaviour> |
40
|
|
|
*/ |
41
|
|
|
protected $behaviours = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var \Romm\Formz\Configuration\Form\Condition\Activation\ActivationResolver |
45
|
|
|
* @validate Romm.Formz:Internal\ConditionIsValid |
46
|
|
|
*/ |
47
|
|
|
protected $activation; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var \Romm\Formz\Configuration\Form\Field\Settings\FieldSettings |
51
|
|
|
*/ |
52
|
|
|
protected $settings; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Name of the field. By default, it is the key of this field in the array |
56
|
|
|
* containing all the fields for the parent form. |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
private $fieldName; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Constructor. |
64
|
|
|
*/ |
65
|
|
|
public function __construct() |
66
|
|
|
{ |
67
|
|
|
$this->settings = new FieldSettings(); |
68
|
|
|
$this->settings->setParents([$this]); |
69
|
|
|
|
70
|
|
|
$this->activation = EmptyActivation::get(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return Form |
75
|
|
|
*/ |
76
|
|
|
public function getForm() |
77
|
|
|
{ |
78
|
|
|
return $this->getFirstParent(Form::class); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $validationName |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function hasValidation($validationName) |
86
|
|
|
{ |
87
|
|
|
return true === isset($this->validation[$validationName]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return Validation[] |
92
|
|
|
*/ |
93
|
|
|
public function getValidation() |
94
|
|
|
{ |
95
|
|
|
return $this->validation; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param Validation $validation |
100
|
|
|
*/ |
101
|
|
|
public function addValidation(Validation $validation) |
102
|
|
|
{ |
103
|
|
|
$this->validation[$validation->getValidationName()] = $validation; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param $validationName |
108
|
|
|
* @return Validation |
109
|
|
|
* @throws EntryNotFoundException |
110
|
|
|
*/ |
111
|
|
|
public function getValidationByName($validationName) |
112
|
|
|
{ |
113
|
|
|
if (false === $this->hasValidation($validationName)) { |
114
|
|
|
throw new EntryNotFoundException( |
115
|
|
|
'The validation "' . $validationName . '" was not found. Please use the function "hasValidation()" befo', |
116
|
|
|
1487672276 |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $this->validation[$validationName]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return Behaviour[] |
125
|
|
|
*/ |
126
|
|
|
public function getBehaviours() |
127
|
|
|
{ |
128
|
|
|
return $this->behaviours; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return ActivationInterface |
133
|
|
|
*/ |
134
|
|
|
public function getActivation() |
135
|
|
|
{ |
136
|
|
|
return $this->activation; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return bool |
141
|
|
|
*/ |
142
|
|
|
public function hasActivation() |
143
|
|
|
{ |
144
|
|
|
return !($this->activation instanceof EmptyActivation); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param ActivationInterface $activation |
149
|
|
|
*/ |
150
|
|
|
public function setActivation(ActivationInterface $activation) |
151
|
|
|
{ |
152
|
|
|
$activation->setRootObject($this); |
153
|
|
|
|
154
|
|
|
$this->activation = $activation; |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return FieldSettings |
159
|
|
|
*/ |
160
|
|
|
public function getSettings() |
161
|
|
|
{ |
162
|
|
|
return $this->settings; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getFieldName() |
169
|
|
|
{ |
170
|
|
|
if (null === $this->fieldName) { |
171
|
|
|
$this->fieldName = $this->getArrayIndex(); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $this->fieldName; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $fieldName |
179
|
|
|
*/ |
180
|
|
|
public function setFieldName($fieldName) |
181
|
|
|
{ |
182
|
|
|
$this->fieldName = $fieldName; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.