Completed
Push — middleware-wip-tmp ( d8f2e1 )
by Romain
02:50
created

FormTrait::setFormObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

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