Completed
Push — wip/steps ( c8af11...06abc1 )
by Romain
02:53
created

FormTrait::getCurrentSubstep()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
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\Definition\Step\Step\Substep\SubstepDefinition;
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 FormMetadataObject
42
     */
43
    public function getMetadata()
44
    {
45
        return $this->getFormObject()->getFormMetadata();
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getFormHash()
52
    {
53
        return $this->getFormObject()->getFormHash();
54
    }
55
56
    /**
57
     * @return FormResult
58
     */
59
    public function getValidationResult()
60
    {
61
        return $this->getFormObject()->getFormResult();
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function getPersistent()
68
    {
69
        return $this->getFormObject()->isPersistent();
70
    }
71
72
    /**
73
     * @return SubstepDefinition
74
     */
75
    public function getCurrentSubstep()
76
    {
77
        return FormObjectFactory::get()->getStepService($this->getFormObject())->getCurrentSubstepDefinition();
78
79
    }
80
81
    /**
82
     * @return FormObject
83
     * @throws EntryNotFoundException
84
     */
85
    private function getFormObject()
86
    {
87
        /** @var FormInterface $this */
88
        return FormObjectFactory::get()->getInstanceWithFormInstance($this);
89
    }
90
91
    /**
92
     * @deprecated This method is deprecated and will be deleted in FormZ v2.
93
     *
94
     * @param string $key
95
     * @return array
96
     */
97
    public function getValidationData($key = null)
98
    {
99
        GeneralUtility::logDeprecatedFunction();
100
101
        $result = $this->validationData;
102
103
        if (null !== $key) {
104
            $result = (isset($this->validationData[$key]))
105
                ? $result = $this->validationData[$key]
106
                : null;
107
        }
108
109
        return $result;
110
    }
111
112
    /**
113
     * @deprecated This method is deprecated and will be deleted in FormZ v2.
114
     *
115
     * @param array $validationData
116
     * @internal
117
     */
118
    public function setValidationData(array $validationData)
119
    {
120
        GeneralUtility::logDeprecatedFunction();
121
122
        $this->validationData = $validationData;
123
    }
124
}
125