Completed
Push — middleware-wip ( ab9573...668c38 )
by Romain
10:14
created

FormTrait::getValidationResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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