|
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\Exceptions\DuplicateEntryException; |
|
17
|
|
|
use Romm\Formz\Form\FormObject; |
|
18
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* This class contains methods that help view helpers to manipulate data and |
|
22
|
|
|
* know more things concerning the current form state. |
|
23
|
|
|
* |
|
24
|
|
|
* It is mainly configured inside the `FormViewHelper`, and used in other |
|
25
|
|
|
* view helpers. |
|
26
|
|
|
*/ |
|
27
|
|
|
class FormViewHelperService implements SingletonInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var bool |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $formContext = false; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var FormObject |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $formObject; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Reset every state that can be used by this service. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function resetState() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->formContext = false; |
|
45
|
|
|
$this->formObject = null; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Will activate the form context, changing the result returned by the |
|
50
|
|
|
* function `formContextExists()`. |
|
51
|
|
|
* |
|
52
|
|
|
* @return FormViewHelperService |
|
53
|
|
|
* @throws DuplicateEntryException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function activateFormContext() |
|
56
|
|
|
{ |
|
57
|
|
|
if (true === $this->formContext) { |
|
58
|
|
|
throw DuplicateEntryException::duplicatedFormContext(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->formContext = true; |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns `true` if the `FormViewHelper` context exists. |
|
68
|
|
|
* |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
|
|
public function formContextExists() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->formContext; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return FormObject |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getFormObject() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->formObject; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param FormObject $formObject |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setFormObject(FormObject $formObject) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->formObject = $formObject; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|