Completed
Push — middleware-wip ( 9fd801...caa06b )
by Romain
03:05
created

FormTrait::isPersistent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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