|
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\Error; |
|
15
|
|
|
|
|
16
|
|
|
use Romm\Formz\Configuration\Form\Field\Field; |
|
17
|
|
|
use Romm\Formz\Configuration\Form\Field\Validation\Validation; |
|
18
|
|
|
use Romm\Formz\Service\Traits\StoreDataTrait; |
|
19
|
|
|
use TYPO3\CMS\Extbase\Error\Result; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Result used when validating a form instance; it provides more features than |
|
23
|
|
|
* the classic Extbase `Result` instance. |
|
24
|
|
|
*/ |
|
25
|
|
|
class FormResult extends Result |
|
26
|
|
|
{ |
|
27
|
|
|
use StoreDataTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Field[] |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $deactivatedFields = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var Validation[] |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $deactivatedFieldsValidation = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Flags the given field as deactivated. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Field $field |
|
43
|
|
|
*/ |
|
44
|
|
|
public function deactivateField(Field $field) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->deactivatedFields[$field->getFieldName()] = $field; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns true if the given field is flagged as deactivated. |
|
51
|
|
|
* |
|
52
|
|
|
* @param Field $field |
|
53
|
|
|
* @return bool |
|
54
|
|
|
*/ |
|
55
|
|
|
public function fieldIsDeactivated(Field $field) |
|
56
|
|
|
{ |
|
57
|
|
|
return array_key_exists($field->getFieldName(), $this->deactivatedFields); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return Field[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getDeactivatedFields() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->deactivatedFields; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Validation $validation |
|
70
|
|
|
*/ |
|
71
|
|
|
public function deactivateValidation(Validation $validation) |
|
72
|
|
|
{ |
|
73
|
|
|
$fieldName = $validation->getParentField()->getFieldName(); |
|
74
|
|
|
|
|
75
|
|
|
if (false === isset($this->deactivatedFieldsValidation[$fieldName])) { |
|
76
|
|
|
$this->deactivatedFieldsValidation[$fieldName] = []; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->deactivatedFieldsValidation[$fieldName][$validation->getValidationName()] = $validation; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param Validation $validation |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function validationIsDeactivated(Validation $validation) |
|
87
|
|
|
{ |
|
88
|
|
|
$fieldName = $validation->getParentField()->getFieldName(); |
|
89
|
|
|
|
|
90
|
|
|
return array_key_exists($fieldName, $this->deactivatedFieldsValidation) |
|
91
|
|
|
&& array_key_exists($validation->getValidationName(), $this->deactivatedFieldsValidation[$fieldName]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return Validation[] |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getDeactivatedValidations() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->deactivatedFieldsValidation; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|