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; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\ConfigurationObjectInterface; |
17
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor; |
18
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface; |
19
|
|
|
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait; |
20
|
|
|
use Romm\ConfigurationObject\Service\ServiceFactory; |
21
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\ArrayConversionTrait; |
22
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\DefaultConfigurationObjectTrait; |
23
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait; |
24
|
|
|
use Romm\Formz\Condition\Items\ConditionItemInterface; |
25
|
|
|
use Romm\Formz\Configuration\AbstractFormzConfiguration; |
26
|
|
|
use Romm\Formz\Configuration\Configuration; |
27
|
|
|
use Romm\Formz\Configuration\Form\Field\Field; |
28
|
|
|
use Romm\Formz\Configuration\Form\Settings\FormSettings; |
29
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
31
|
|
|
use TYPO3\CMS\Extbase\Validation\Error; |
32
|
|
|
|
33
|
|
|
class Form extends AbstractFormzConfiguration implements ConfigurationObjectInterface, DataPreProcessorInterface |
34
|
|
|
{ |
35
|
|
|
use DefaultConfigurationObjectTrait; |
36
|
|
|
use StoreArrayIndexTrait; |
37
|
|
|
use ParentsTrait; |
38
|
|
|
use ArrayConversionTrait; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \Romm\Formz\Configuration\Form\Field\Field[] |
42
|
|
|
* @validate NotEmpty |
43
|
|
|
*/ |
44
|
|
|
protected $fields = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ConditionItemInterface[] |
48
|
|
|
* @mixedTypesResolver \Romm\Formz\Configuration\Form\Condition\ConditionItemResolver |
49
|
|
|
*/ |
50
|
|
|
protected $conditionList = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \Romm\Formz\Configuration\Form\Settings\FormSettings |
54
|
|
|
*/ |
55
|
|
|
protected $settings; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Constructor. |
59
|
|
|
*/ |
60
|
|
|
public function __construct() |
61
|
|
|
{ |
62
|
|
|
$this->settings = GeneralUtility::makeInstance(FormSettings::class); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Will initialize correctly the configuration object settings. |
67
|
|
|
* |
68
|
|
|
* @return ServiceFactory |
69
|
|
|
*/ |
70
|
|
|
public static function getConfigurationObjectServices() |
71
|
|
|
{ |
72
|
|
|
return Configuration::getConfigurationObjectServices(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns FormZ root configuration object. |
77
|
|
|
* |
78
|
|
|
* @return Configuration |
79
|
|
|
*/ |
80
|
|
|
public function getRootConfiguration() |
81
|
|
|
{ |
82
|
|
|
return $this->getFirstParent(Configuration::class); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return Field[] |
87
|
|
|
*/ |
88
|
|
|
public function getFields() |
89
|
|
|
{ |
90
|
|
|
return $this->fields; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $name |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function hasField($name) |
98
|
|
|
{ |
99
|
|
|
return true === isset($this->fields[$name]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $name |
104
|
|
|
* @return Field |
105
|
|
|
* @throws EntryNotFoundException |
106
|
|
|
*/ |
107
|
|
|
public function getField($name) |
108
|
|
|
{ |
109
|
|
|
if (false === $this->hasField($name)) { |
110
|
|
|
throw EntryNotFoundException::configurationFieldNotFound($name); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $this->fields[$name]; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param Field $field |
118
|
|
|
*/ |
119
|
|
|
public function addField(Field $field) |
120
|
|
|
{ |
121
|
|
|
$this->fields[$field->getName()] = $field; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return ConditionItemInterface[] |
126
|
|
|
*/ |
127
|
|
|
public function getConditionList() |
128
|
|
|
{ |
129
|
|
|
return $this->conditionList; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $name |
134
|
|
|
* @param ConditionItemInterface $condition |
135
|
|
|
*/ |
136
|
|
|
public function addCondition($name, ConditionItemInterface $condition) |
137
|
|
|
{ |
138
|
|
|
$this->conditionList[$name] = $condition; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return FormSettings |
143
|
|
|
*/ |
144
|
|
|
public function getSettings() |
145
|
|
|
{ |
146
|
|
|
return $this->settings; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param DataPreProcessor $processor |
151
|
|
|
*/ |
152
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
153
|
|
|
{ |
154
|
|
|
$data = $processor->getData(); |
155
|
|
|
|
156
|
|
|
if (isset($data['activationCondition'])) { |
157
|
|
|
$error = new Error( |
158
|
|
|
'The property "activationCondition" has been deprecated and renamed to "conditionList", please change your TypoScript configuration.', |
159
|
|
|
1489763042 |
160
|
|
|
); |
161
|
|
|
$processor->addError($error); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|