Completed
Push — unit-tests-conditions ( a23049...dc9eee )
by Romain
02:30
created

FieldViewHelperService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 69
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A resetState() 0 5 1
A fieldContextExists() 0 4 1
A getCurrentField() 0 4 1
A setCurrentField() 0 4 1
A setFieldOption() 0 4 1
A getFieldOptions() 0 4 1
1
<?php
2
/*
3
 * 2016 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\Service\ViewHelper;
15
16
use Romm\Formz\Configuration\Form\Field\Field;
17
use TYPO3\CMS\Core\SingletonInterface;
18
19
/**
20
 * Contains methods to help view helpers to manipulate data concerning the
21
 * current field.
22
 */
23
class FieldViewHelperService implements SingletonInterface
24
{
25
    /**
26
     * @var Field
27
     */
28
    protected $currentField;
29
30
    /**
31
     * @var array
32
     */
33
    protected $fieldOptions = [];
34
35
    /**
36
     * Reset every state that can be used by this service.
37
     */
38
    public function resetState()
39
    {
40
        $this->currentField = null;
41
        $this->fieldOptions = [];
42
    }
43
44
    /**
45
     * Checks that the `FieldViewHelper` has been called. If not, an exception
46
     * is thrown.
47
     *
48
     * @return bool
49
     */
50
    public function fieldContextExists()
51
    {
52
        return $this->currentField instanceof Field;
53
    }
54
55
    /**
56
     * Returns the current field which was defined by the `FieldViewHelper`.
57
     *
58
     * Returns null if no current field was found.
59
     *
60
     * @return Field|null
61
     */
62
    public function getCurrentField()
63
    {
64
        return $this->currentField;
65
    }
66
67
    /**
68
     * @param Field $field
69
     */
70
    public function setCurrentField(Field $field)
71
    {
72
        $this->currentField = $field;
73
    }
74
75
    /**
76
     * @param string $name
77
     * @param mixed  $value
78
     */
79
    public function setFieldOption($name, $value)
80
    {
81
        $this->fieldOptions[$name] = $value;
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function getFieldOptions()
88
    {
89
        return $this->fieldOptions;
90
    }
91
}
92