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; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Exceptions\DuplicateEntryException; |
17
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This trait should be used by default to implement all the functions required |
22
|
|
|
* by the interface `FormInterface`. |
23
|
|
|
* |
24
|
|
|
* This is not advised to overrides the function provided by this trait, unless |
25
|
|
|
* you know what you are doing. |
26
|
|
|
*/ |
27
|
|
|
trait FormTrait |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var FormObject |
31
|
|
|
*/ |
32
|
|
|
private $formObject; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Contains the optional data returned from the validators of each field. |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $validationData = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param FormObject $formObject |
43
|
|
|
* @throws DuplicateEntryException |
44
|
|
|
*/ |
45
|
|
|
public function setFormObject(FormObject $formObject) |
46
|
|
|
{ |
47
|
|
|
if (null !== $this->formObject) { |
48
|
|
|
throw DuplicateEntryException::formObjectAlreadyInjected(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->formObject = $formObject; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return FormObject |
56
|
|
|
* @throws EntryNotFoundException |
57
|
|
|
*/ |
58
|
|
|
protected function getFormObject() |
59
|
|
|
{ |
60
|
|
|
if (null === $this->formObject) { |
61
|
|
|
throw EntryNotFoundException::formObjectNotFound($this); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this->formObject; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getFormIdentifier() |
71
|
|
|
{ |
72
|
|
|
return $this->getFormObject()->getFormIdentifierHash(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @deprecated This method is deprecated since FormZ v2, and will be deleted in FormZ v3. |
77
|
|
|
* |
78
|
|
|
* @param string $key |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getValidationData($key = null) |
82
|
|
|
{ |
83
|
|
|
GeneralUtility::logDeprecatedFunction(); |
84
|
|
|
|
85
|
|
|
$result = $this->validationData; |
86
|
|
|
|
87
|
|
|
if (null !== $key) { |
88
|
|
|
$result = (isset($this->validationData[$key])) |
89
|
|
|
? $result = $this->validationData[$key] |
90
|
|
|
: null; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $result; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @deprecated This method is deprecated since FormZ v2, and will be deleted in FormZ v3. |
98
|
|
|
* |
99
|
|
|
* @param array $validationData |
100
|
|
|
* @internal |
101
|
|
|
*/ |
102
|
|
|
public function setValidationData(array $validationData) |
103
|
|
|
{ |
104
|
|
|
GeneralUtility::logDeprecatedFunction(); |
105
|
|
|
|
106
|
|
|
$this->validationData = $validationData; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|