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\Configuration\View; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Configuration\AbstractFormzConfiguration; |
17
|
|
|
use Romm\Formz\Configuration\View\Classes\Classes; |
18
|
|
|
use Romm\Formz\Configuration\View\Layouts\LayoutGroup; |
19
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
20
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
21
|
|
|
|
22
|
|
|
class View extends AbstractFormzConfiguration |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \Romm\Formz\Configuration\View\Classes\Classes |
27
|
|
|
*/ |
28
|
|
|
protected $classes; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Romm\Formz\Configuration\View\Layouts\LayoutGroup[] |
32
|
|
|
*/ |
33
|
|
|
protected $layouts = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
* @validate NotEmpty |
38
|
|
|
*/ |
39
|
|
|
protected $layoutRootPaths = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
* @validate NotEmpty |
44
|
|
|
*/ |
45
|
|
|
protected $partialRootPaths = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Constructor. |
49
|
|
|
*/ |
50
|
|
|
public function __construct() |
51
|
|
|
{ |
52
|
|
|
$this->classes = GeneralUtility::makeInstance(Classes::class); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return Classes |
57
|
|
|
*/ |
58
|
|
|
public function getClasses() |
59
|
|
|
{ |
60
|
|
|
return $this->classes; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $name |
65
|
|
|
* @param LayoutGroup $layout |
66
|
|
|
*/ |
67
|
|
|
public function setLayout($name, LayoutGroup $layout) |
68
|
|
|
{ |
69
|
|
|
$this->layouts[$name] = $layout; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return LayoutGroup[] |
74
|
|
|
*/ |
75
|
|
|
public function getLayouts() |
76
|
|
|
{ |
77
|
|
|
return $this->layouts; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $name |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function hasLayout($name) |
85
|
|
|
{ |
86
|
|
|
return true === isset($this->layouts[$name]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $name |
91
|
|
|
* @return LayoutGroup |
92
|
|
|
* @throws EntryNotFoundException |
93
|
|
|
*/ |
94
|
|
|
public function getLayout($name) |
95
|
|
|
{ |
96
|
|
|
if (false === $this->hasLayout($name)) { |
97
|
|
|
throw EntryNotFoundException::viewLayoutNotFound($name); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->layouts[$name]; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $key |
105
|
|
|
* @param string $path |
106
|
|
|
*/ |
107
|
|
|
public function setLayoutRootPath($key, $path) |
108
|
|
|
{ |
109
|
|
|
$this->layoutRootPaths[$key] = $path; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function getLayoutRootPaths() |
116
|
|
|
{ |
117
|
|
|
return $this->layoutRootPaths; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
|
|
public function getAbsoluteLayoutRootPaths() |
124
|
|
|
{ |
125
|
|
|
$paths = $this->layoutRootPaths; |
126
|
|
|
|
127
|
|
|
foreach ($paths as $key => $path) { |
128
|
|
|
$paths[$key] = $this->getAbsolutePath($path); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return $paths; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param string $key |
136
|
|
|
* @param string $path |
137
|
|
|
*/ |
138
|
|
|
public function setPartialRootPath($key, $path) |
139
|
|
|
{ |
140
|
|
|
$this->partialRootPaths[$key] = $path; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
public function getPartialRootPaths() |
147
|
|
|
{ |
148
|
|
|
return $this->partialRootPaths; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return array |
153
|
|
|
*/ |
154
|
|
|
public function getAbsolutePartialRootPaths() |
155
|
|
|
{ |
156
|
|
|
$paths = $this->partialRootPaths; |
157
|
|
|
|
158
|
|
|
foreach ($paths as $key => $path) { |
159
|
|
|
$paths[$key] = $this->getAbsolutePath($path); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $paths; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $path |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
protected function getAbsolutePath($path) |
170
|
|
|
{ |
171
|
|
|
return GeneralUtility::getFileAbsFileName($path); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|