1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Admin\View; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Admin; |
5
|
|
|
use Redaxscript\Dater; |
6
|
|
|
use Redaxscript\Html; |
7
|
|
|
use Redaxscript\Module; |
8
|
|
|
use Redaxscript\Validator; |
9
|
|
|
use function count; |
10
|
|
|
use function htmlspecialchars; |
11
|
|
|
use function json_decode; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* children class to create the extra form |
15
|
|
|
* |
16
|
|
|
* @since 3.0.0 |
17
|
|
|
* |
18
|
|
|
* @package Redaxscript |
19
|
|
|
* @category View |
20
|
|
|
* @author Henry Ruhs |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class ExtraForm extends ViewAbstract |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* render the view |
27
|
|
|
* |
28
|
|
|
* @since 3.0.0 |
29
|
|
|
* |
30
|
|
|
* @param int $extraId identifier of the extra |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
|
35
|
4 |
|
public function render(int $extraId = null) : string |
36
|
|
|
{ |
37
|
4 |
|
$output = Module\Hook::trigger('adminExtraFormStart'); |
38
|
4 |
|
$helperOption = new Helper\Option($this->_language); |
39
|
4 |
|
$extraModel = new Admin\Model\Extra(); |
40
|
4 |
|
$extra = $extraModel->getById($extraId); |
41
|
4 |
|
$nameValidator = new Validator\Name(); |
42
|
4 |
|
$aliasValidator = new Validator\Alias(); |
43
|
4 |
|
$dater = new Dater(); |
44
|
4 |
|
$dater->init($extra->date); |
45
|
|
|
|
46
|
|
|
/* html element */ |
47
|
|
|
|
48
|
4 |
|
$titleElement = new Html\Element(); |
49
|
|
|
$titleElement |
50
|
4 |
|
->init('h2', |
51
|
|
|
[ |
52
|
4 |
|
'class' => 'rs-admin-title-content', |
53
|
|
|
]) |
54
|
4 |
|
->text($extra->title ? : $this->_language->get('extra_new')); |
55
|
4 |
|
$formElement = new Admin\Html\Form($this->_registry, $this->_language); |
56
|
4 |
|
$formElement->init( |
57
|
|
|
[ |
58
|
4 |
|
'form' => |
59
|
|
|
[ |
60
|
|
|
'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default rs-admin-form-extra' |
61
|
|
|
], |
62
|
|
|
'button' => |
63
|
|
|
[ |
64
|
|
|
'create' => |
65
|
|
|
[ |
66
|
|
|
'name' => self::class |
67
|
|
|
], |
68
|
|
|
'save' => |
69
|
|
|
[ |
70
|
|
|
'name' => self::class |
71
|
|
|
] |
72
|
|
|
], |
73
|
|
|
'link' => |
74
|
|
|
[ |
75
|
|
|
'cancel' => |
76
|
|
|
[ |
77
|
4 |
|
'href' => $this->_registry->get('extrasEdit') && $this->_registry->get('extrasDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/extras' : $this->_registry->get('parameterRoute') . 'admin' |
78
|
|
|
], |
79
|
|
|
'delete' => |
80
|
|
|
[ |
81
|
4 |
|
'href' => $extra->id ? $this->_registry->get('parameterRoute') . 'admin/delete/extras/' . $extra->id . '/' . $this->_registry->get('token') : null |
82
|
|
|
] |
83
|
|
|
] |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
/* create the form */ |
87
|
|
|
|
88
|
|
|
$formElement |
89
|
|
|
|
90
|
|
|
/* extra */ |
91
|
|
|
|
92
|
4 |
|
->radio( |
93
|
|
|
[ |
94
|
4 |
|
'id' => self::class . '\Extra', |
95
|
|
|
'class' => 'rs-admin-fn-status-tab', |
96
|
|
|
'name' => self::class . '\Tab', |
97
|
|
|
'checked' => 'checked' |
98
|
|
|
]) |
99
|
4 |
|
->label($this->_language->get('extra'), |
|
|
|
|
100
|
|
|
[ |
101
|
4 |
|
'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
102
|
|
|
'for' => self::class . '\Extra' |
103
|
|
|
]) |
104
|
4 |
|
->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
105
|
4 |
|
->label($this->_language->get('title'), |
|
|
|
|
106
|
|
|
[ |
107
|
4 |
|
'for' => 'title' |
108
|
|
|
]) |
109
|
4 |
|
->text( |
110
|
|
|
[ |
111
|
4 |
|
'autofocus' => 'autofocus', |
112
|
4 |
|
'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text', |
113
|
4 |
|
'id' => 'title', |
114
|
4 |
|
'name' => 'title', |
115
|
4 |
|
'pattern' => $nameValidator->getPattern(), |
116
|
4 |
|
'required' => 'required', |
117
|
4 |
|
'value' => $extra->title |
118
|
|
|
]) |
119
|
4 |
|
->append('</li><li>') |
120
|
4 |
|
->label($this->_language->get('alias'), |
|
|
|
|
121
|
|
|
[ |
122
|
4 |
|
'for' => 'alias' |
123
|
|
|
]) |
124
|
4 |
|
->text( |
125
|
|
|
[ |
126
|
4 |
|
'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text', |
127
|
4 |
|
'id' => 'alias', |
128
|
4 |
|
'name' => 'alias', |
129
|
4 |
|
'pattern' => $aliasValidator->getPattern(), |
130
|
4 |
|
'required' => 'required', |
131
|
4 |
|
'value' => $extra->alias |
132
|
|
|
]) |
133
|
4 |
|
->append('</li><li>') |
134
|
4 |
|
->label($this->_language->get('text'), |
|
|
|
|
135
|
|
|
[ |
136
|
4 |
|
'for' => 'text' |
137
|
|
|
]) |
138
|
4 |
|
->textarea( |
139
|
|
|
[ |
140
|
4 |
|
'class' => 'rs-admin-js-editor rs-admin-js-resize rs-admin-field-textarea', |
141
|
4 |
|
'id' => 'text', |
142
|
4 |
|
'name' => 'text', |
143
|
4 |
|
'required' => 'required', |
144
|
4 |
|
'value' => htmlspecialchars($extra->text, ENT_QUOTES) |
145
|
|
|
]) |
146
|
4 |
|
->append('</li></ul>') |
147
|
|
|
|
148
|
|
|
/* general */ |
149
|
|
|
|
150
|
4 |
|
->radio( |
151
|
|
|
[ |
152
|
4 |
|
'id' => self::class . '\General', |
153
|
|
|
'class' => 'rs-admin-fn-status-tab', |
154
|
|
|
'name' => self::class . '\Tab' |
155
|
|
|
]) |
156
|
4 |
|
->label($this->_language->get('general'), |
|
|
|
|
157
|
|
|
[ |
158
|
4 |
|
'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
159
|
|
|
'for' => self::class . '\General' |
160
|
|
|
]) |
161
|
4 |
|
->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
162
|
4 |
|
->label($this->_language->get('language'), |
|
|
|
|
163
|
|
|
[ |
164
|
4 |
|
'for' => 'language' |
165
|
|
|
]) |
166
|
4 |
|
->select($helperOption->getLanguageArray(), |
167
|
|
|
[ |
168
|
4 |
|
$extra->language |
169
|
|
|
], |
170
|
|
|
[ |
171
|
4 |
|
'id' => 'language', |
172
|
|
|
'name' => 'language' |
173
|
|
|
]) |
174
|
4 |
|
->append('</li><li>') |
175
|
4 |
|
->label($this->_language->get('extra_sibling'), |
|
|
|
|
176
|
|
|
[ |
177
|
4 |
|
'for' => 'sibling' |
178
|
|
|
]) |
179
|
4 |
|
->select($helperOption->getSiblingForExtraArray($extra->id), |
180
|
|
|
[ |
181
|
4 |
|
$extra->sibling |
182
|
|
|
], |
183
|
|
|
[ |
184
|
4 |
|
'id' => 'sibling', |
185
|
|
|
'name' => 'sibling' |
186
|
|
|
]) |
187
|
4 |
|
->append('</li><li>') |
188
|
4 |
|
->label($this->_language->get('category'), |
|
|
|
|
189
|
|
|
[ |
190
|
4 |
|
'for' => 'category' |
191
|
|
|
]) |
192
|
4 |
|
->select($helperOption->getCategoryArray(), |
193
|
|
|
[ |
194
|
4 |
|
$extra->category |
195
|
|
|
], |
196
|
|
|
[ |
197
|
4 |
|
'id' => 'category', |
198
|
|
|
'name' => 'category' |
199
|
|
|
]) |
200
|
4 |
|
->append('</li><li>') |
201
|
4 |
|
->label($this->_language->get('article'), |
|
|
|
|
202
|
|
|
[ |
203
|
4 |
|
'for' => 'article' |
204
|
|
|
]) |
205
|
4 |
|
->select($helperOption->getArticleArray(), |
206
|
|
|
[ |
207
|
4 |
|
$extra->article |
208
|
|
|
], |
209
|
|
|
[ |
210
|
4 |
|
'id' => 'article', |
211
|
|
|
'name' => 'article' |
212
|
|
|
]) |
213
|
4 |
|
->append('</li></ul>') |
214
|
|
|
|
215
|
|
|
/* customize */ |
216
|
|
|
|
217
|
4 |
|
->radio( |
218
|
|
|
[ |
219
|
4 |
|
'id' => self::class . '\Customize', |
220
|
|
|
'class' => 'rs-admin-fn-status-tab', |
221
|
|
|
'name' => self::class . '\Tab' |
222
|
|
|
]) |
223
|
4 |
|
->label($this->_language->get('customize'), |
|
|
|
|
224
|
|
|
[ |
225
|
4 |
|
'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab', |
226
|
|
|
'for' => self::class . '\Customize' |
227
|
|
|
]) |
228
|
4 |
|
->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>') |
229
|
4 |
|
->label($this->_language->get('headline'), |
|
|
|
|
230
|
|
|
[ |
231
|
4 |
|
'for' => 'headline' |
232
|
|
|
]) |
233
|
4 |
|
->checkbox(!$extra->id || $extra->headline ? |
234
|
|
|
[ |
235
|
4 |
|
'id' => 'headline', |
236
|
|
|
'class' => 'rs-admin-fn-status-switch', |
237
|
|
|
'name' => 'headline', |
238
|
|
|
'checked' => 'checked' |
239
|
|
|
] : |
240
|
|
|
[ |
241
|
4 |
|
'id' => 'headline', |
242
|
|
|
'class' => 'rs-admin-fn-status-switch', |
243
|
|
|
'name' => 'headline' |
244
|
|
|
]) |
245
|
4 |
|
->label(null, |
246
|
|
|
[ |
247
|
4 |
|
'class' => 'rs-admin-label-switch', |
248
|
4 |
|
'for' => 'headline', |
249
|
4 |
|
'data-on' => $this->_language->get('enable'), |
250
|
4 |
|
'data-off' => $this->_language->get('disable') |
251
|
|
|
]) |
252
|
4 |
|
->append('</li><li>') |
253
|
4 |
|
->label($this->_language->get('status'), |
|
|
|
|
254
|
|
|
[ |
255
|
4 |
|
'for' => 'status' |
256
|
|
|
]) |
257
|
4 |
|
->checkbox(!$extra->id || $extra->status ? |
258
|
|
|
[ |
259
|
4 |
|
'id' => 'status', |
260
|
|
|
'class' => 'rs-admin-fn-status-switch', |
261
|
|
|
'name' => 'status', |
262
|
|
|
'checked' => 'checked' |
263
|
|
|
] : |
264
|
|
|
[ |
265
|
4 |
|
'id' => 'status', |
266
|
|
|
'class' => 'rs-admin-fn-status-switch', |
267
|
|
|
'name' => 'status' |
268
|
|
|
]) |
269
|
4 |
|
->label(null, |
270
|
|
|
[ |
271
|
4 |
|
'class' => 'rs-admin-label-switch', |
272
|
4 |
|
'for' => 'status', |
273
|
4 |
|
'data-on' => $this->_language->get('publish'), |
274
|
4 |
|
'data-off' => $this->_language->get('unpublish') |
275
|
|
|
]) |
276
|
4 |
|
->append('</li><li>') |
277
|
4 |
|
->label($this->_language->get('rank'), |
|
|
|
|
278
|
|
|
[ |
279
|
4 |
|
'for' => 'rank' |
280
|
|
|
]) |
281
|
4 |
|
->number( |
282
|
|
|
[ |
283
|
4 |
|
'id' => 'rank', |
284
|
4 |
|
'name' => 'rank', |
285
|
4 |
|
'value' => $extra->id ? $extra->rank : $extraModel->query()->max('rank') + 1 |
286
|
|
|
]) |
287
|
4 |
|
->append('</li>'); |
288
|
4 |
|
if ($this->_registry->get('groupsEdit')) |
289
|
|
|
{ |
290
|
|
|
$formElement |
291
|
4 |
|
->append('<li>') |
292
|
4 |
|
->label($this->_language->get('access'), |
|
|
|
|
293
|
|
|
[ |
294
|
4 |
|
'for' => 'access' |
295
|
|
|
]) |
296
|
4 |
|
->select($helperOption->getGroupArray(), |
297
|
4 |
|
(array)json_decode($extra->access), |
298
|
|
|
[ |
299
|
4 |
|
'id' => 'access', |
300
|
4 |
|
'name' => 'access[]', |
301
|
4 |
|
'multiple' => 'multiple', |
302
|
4 |
|
'size' => count($helperOption->getGroupArray()) |
303
|
|
|
]) |
304
|
4 |
|
->append('</li>'); |
305
|
|
|
} |
306
|
|
|
$formElement |
307
|
4 |
|
->append('<li>') |
308
|
4 |
|
->label($this->_language->get('date'), |
|
|
|
|
309
|
|
|
[ |
310
|
4 |
|
'for' => 'date' |
311
|
|
|
]) |
312
|
4 |
|
->datetime( |
313
|
|
|
[ |
314
|
4 |
|
'id' => 'date', |
315
|
4 |
|
'name' => 'date', |
316
|
4 |
|
'value' => $dater->formatField() |
317
|
|
|
]) |
318
|
4 |
|
->append('</li></ul>') |
319
|
4 |
|
->hidden( |
320
|
|
|
[ |
321
|
4 |
|
'name' => 'id', |
322
|
4 |
|
'value' => $extra->id |
323
|
|
|
]) |
324
|
4 |
|
->token() |
325
|
4 |
|
->append('<div class="rs-admin-wrapper-button">') |
326
|
4 |
|
->cancel(); |
327
|
4 |
|
if ($extra->id) |
328
|
|
|
{ |
329
|
2 |
|
if ($this->_registry->get('extrasDelete')) |
330
|
|
|
{ |
331
|
1 |
|
$formElement->delete(); |
332
|
|
|
} |
333
|
2 |
|
if ($this->_registry->get('extrasEdit')) |
334
|
|
|
{ |
335
|
2 |
|
$formElement->save(); |
336
|
|
|
} |
337
|
|
|
} |
338
|
2 |
|
else if ($this->_registry->get('extrasNew')) |
339
|
|
|
{ |
340
|
1 |
|
$formElement->create(); |
341
|
|
|
} |
342
|
4 |
|
$formElement->append('</div>'); |
343
|
|
|
|
344
|
|
|
/* collect output */ |
345
|
|
|
|
346
|
4 |
|
$output .= $titleElement . $formElement; |
347
|
4 |
|
$output .= Module\Hook::trigger('adminExtraFormEnd'); |
348
|
4 |
|
return $output; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.