|
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\Parents\ParentsTrait; |
|
18
|
|
|
use Romm\ConfigurationObject\Service\ServiceFactory; |
|
19
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\ArrayConversionTrait; |
|
20
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\DefaultConfigurationObjectTrait; |
|
21
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait; |
|
22
|
|
|
use Romm\Formz\Configuration\AbstractFormzConfiguration; |
|
23
|
|
|
use Romm\Formz\Configuration\Configuration; |
|
24
|
|
|
use Romm\Formz\Configuration\Form\Condition\ConditionItemResolver; |
|
25
|
|
|
use Romm\Formz\Configuration\Form\Field\Field; |
|
26
|
|
|
use Romm\Formz\Configuration\Form\Settings\FormSettings; |
|
27
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
28
|
|
|
|
|
29
|
|
|
class Form extends AbstractFormzConfiguration implements ConfigurationObjectInterface |
|
30
|
|
|
{ |
|
31
|
|
|
use DefaultConfigurationObjectTrait; |
|
32
|
|
|
use StoreArrayIndexTrait; |
|
33
|
|
|
use ParentsTrait; |
|
34
|
|
|
use ArrayConversionTrait; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var \ArrayObject<Romm\Formz\Configuration\Form\Field\Field> |
|
38
|
|
|
* @validate NotEmpty |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $fields = []; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var \ArrayObject<Romm\Formz\Configuration\Form\Condition\ConditionItemResolver> |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $activationCondition = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var \Romm\Formz\Configuration\Form\Settings\FormSettings |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $settings; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Constructor. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->settings = GeneralUtility::makeInstance(FormSettings::class); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Will initialize correctly the configuration object settings. |
|
62
|
|
|
* |
|
63
|
|
|
* @return ServiceFactory |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function getConfigurationObjectServices() |
|
66
|
|
|
{ |
|
67
|
|
|
return Configuration::getConfigurationObjectServices(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the root configuration object of Formz. |
|
72
|
|
|
* |
|
73
|
|
|
* @return Configuration |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getFormzConfiguration() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->getFirstParent(Configuration::class); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return Field[] |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getFields() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->fields; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $fieldName |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
public function hasField($fieldName) |
|
93
|
|
|
{ |
|
94
|
|
|
return true === isset($this->fields[$fieldName]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $fieldName |
|
99
|
|
|
* @return Field|null |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getField($fieldName) |
|
102
|
|
|
{ |
|
103
|
|
|
$result = null; |
|
104
|
|
|
|
|
105
|
|
|
if ($this->hasField($fieldName)) { |
|
106
|
|
|
$result = $this->fields[$fieldName]; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $result; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param Field $field |
|
114
|
|
|
*/ |
|
115
|
|
|
public function addField(Field $field) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->fields[$field->getFieldName()] = $field; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return ConditionItemResolver[] |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getActivationCondition() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->activationCondition; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return FormSettings |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getSettings() |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->settings; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|