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