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 array |
31
|
|
|
*/ |
32
|
|
|
protected $deactivatedFields = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
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()] = true; |
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
|
|
|
* @param Validation $validation |
62
|
|
|
*/ |
63
|
|
|
public function deactivateValidation(Validation $validation) |
64
|
|
|
{ |
65
|
|
|
$fieldName = $validation->getParentField()->getFieldName(); |
66
|
|
|
|
67
|
|
|
if (false === isset($this->deactivatedFieldsValidation[$fieldName])) { |
68
|
|
|
$this->deactivatedFieldsValidation[$fieldName] = []; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->deactivatedFieldsValidation[$fieldName][$validation->getValidationName()] = true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param Validation $validation |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function validationIsDeactivated(Validation $validation) |
79
|
|
|
{ |
80
|
|
|
$fieldName = $validation->getParentField()->getFieldName(); |
81
|
|
|
|
82
|
|
|
return array_key_exists($fieldName, $this->deactivatedFieldsValidation) |
83
|
|
|
&& array_key_exists($validation->getValidationName(), $this->deactivatedFieldsValidation[$fieldName]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|