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\Form\FormObject\Service; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Configuration\ConfigurationFactory; |
17
|
|
|
use Romm\Formz\Core\Core; |
18
|
|
|
use Romm\Formz\Form\FormObject\Definition\FormDefinitionObject; |
19
|
|
|
use Romm\Formz\Form\FormObject\FormObjectStatic; |
20
|
|
|
use Romm\Formz\Validation\Validator\Internal\FormDefinitionValidator; |
21
|
|
|
use TYPO3\CMS\Extbase\Error\Result; |
22
|
|
|
|
23
|
|
|
class FormObjectConfiguration |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var FormObjectStatic |
27
|
|
|
*/ |
28
|
|
|
protected $static; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var FormDefinitionObject |
32
|
|
|
*/ |
33
|
|
|
protected $definition; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Result |
37
|
|
|
*/ |
38
|
|
|
protected $configurationValidationResult; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param FormObjectStatic $static |
42
|
|
|
* @param FormDefinitionObject $definition |
43
|
|
|
*/ |
44
|
|
|
public function __construct(FormObjectStatic $static, FormDefinitionObject $definition) |
45
|
|
|
{ |
46
|
|
|
$this->static = $static; |
47
|
|
|
$this->definition = $definition; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* This function will merge and return the validation results of both the |
52
|
|
|
* global FormZ configuration object, and this form configuration object. |
53
|
|
|
* |
54
|
|
|
* @return Result |
55
|
|
|
*/ |
56
|
|
|
public function getConfigurationValidationResult() |
57
|
|
|
{ |
58
|
|
|
if (null === $this->configurationValidationResult) { |
59
|
|
|
$this->configurationValidationResult = $this->getMergedValidationResult(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->configurationValidationResult; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Resets the validation result and merges it with the global FormZ |
67
|
|
|
* configuration. |
68
|
|
|
* |
69
|
|
|
* @return Result |
70
|
|
|
*/ |
71
|
|
|
protected function getMergedValidationResult() |
72
|
|
|
{ |
73
|
|
|
$result = new Result; |
74
|
|
|
$formPropertyName = 'forms.' . $this->static->getClassName(); |
75
|
|
|
|
76
|
|
|
$result->merge($this->getGlobalConfigurationValidationResult()); |
77
|
|
|
$result->forProperty($formPropertyName)->merge($this->definition->getValidationResult()); |
78
|
|
|
$result->forProperty($formPropertyName)->merge($this->getFormDefinitionValidationResult()); |
79
|
|
|
|
80
|
|
|
return $result; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return Result |
85
|
|
|
*/ |
86
|
|
|
protected function getFormDefinitionValidationResult() |
87
|
|
|
{ |
88
|
|
|
/** @var FormDefinitionValidator $formDefinitionValidator */ |
89
|
|
|
$formDefinitionValidator = Core::instantiate(FormDefinitionValidator::class); |
90
|
|
|
|
91
|
|
|
return $formDefinitionValidator->validate($this->definition->getObject(true)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Result |
96
|
|
|
*/ |
97
|
|
|
protected function getGlobalConfigurationValidationResult() |
98
|
|
|
{ |
99
|
|
|
return ConfigurationFactory::get()->getFormzConfiguration()->getValidationResult(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|