Completed
Push — master ( 1da492...320203 )
by Henry
07:00
created

includes/Admin/View/CategoryForm.php (16 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 json_decode;
11
12
/**
13
 * children class to create the category form
14
 *
15
 * @since 3.0.0
16
 *
17
 * @package Redaxscript
18
 * @category View
19
 * @author Henry Ruhs
20
 */
21
22
class CategoryForm extends ViewAbstract
23
{
24
	/**
25
	 * render the view
26
	 *
27
	 * @since 3.0.0
28
	 *
29
	 * @param int $categoryId identifier of the category
30
	 *
31
	 * @return string
32
	 */
33
34
	public function render(int $categoryId = null) : string
35
	{
36
		$output = Module\Hook::trigger('adminCategoryFormStart');
37
		$helperOption = new Helper\Option($this->_language);
38
		$categoryModel = new Admin\Model\Category();
39
		$category = $categoryModel->getById($categoryId);
40
		$aliasValidator = new Validator\Alias();
41
		$dater = new Dater();
42
		$dater->init($category->date);
43
44
		/* html element */
45
46
		$titleElement = new Html\Element();
47
		$titleElement
48
			->init('h2',
49
			[
50
				'class' => 'rs-admin-title-content',
51
			])
52
			->text($category->title ? : $this->_language->get('category_new'));
53
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
54
		$formElement->init(
55
		[
56
			'form' =>
57
			[
58
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
59
			],
60
			'button' =>
61
			[
62
				'create' =>
63
				[
64
					'name' => self::class
65
				],
66
				'save' =>
67
				[
68
					'name' => self::class
69
				]
70
			],
71
			'link' =>
72
			[
73
				'cancel' =>
74
				[
75
					'href' => $this->_registry->get('categoriesEdit') && $this->_registry->get('categoriesDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/categories' : $this->_registry->get('parameterRoute') . 'admin'
76
				],
77
				'delete' =>
78
				[
79
					'href' => $category->id ? $this->_registry->get('parameterRoute') . 'admin/delete/categories/' . $category->id . '/' . $this->_registry->get('token') : null
80
				]
81
			]
82
		]);
83
84
		/* create the form */
85
86
		$formElement
87
88
			/* category */
89
90
			->radio(
91
			[
92
				'id' => self::class . '\Category',
93
				'class' => 'rs-admin-fn-status-tab',
94
				'name' => self::class . '\Tab',
95
				'checked' => 'checked'
96
			])
97
			->label($this->_language->get('category'),
0 ignored issues
show
It seems like $this->_language->get('category') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
98
			[
99
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
100
				'for' => self::class . '\Category'
101
			])
102
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
103
			->label($this->_language->get('title'),
0 ignored issues
show
It seems like $this->_language->get('title') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
104
			[
105
				'for' => 'title'
106
			])
107
			->text(
108
			[
109
				'autofocus' => 'autofocus',
110
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
111
				'id' => 'title',
112
				'name' => 'title',
113
				'required' => 'required',
114
				'value' => $category->title
115
			])
116
			->append('</li><li>')
117
			->label($this->_language->get('alias'),
0 ignored issues
show
It seems like $this->_language->get('alias') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
118
			[
119
				'for' => 'alias'
120
			])
121
			->text(
122
			[
123
				'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
124
				'id' => 'alias',
125
				'name' => 'alias',
126
				'pattern' => $aliasValidator->getFormPattern(),
127
				'required' => 'required',
128
				'value' => $category->alias
129
			])
130
			->append('</li><li>')
131
			->label($this->_language->get('description'),
0 ignored issues
show
It seems like $this->_language->get('description') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
132
			[
133
				'for' => 'description'
134
			])
135
			->textarea(
136
			[
137
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
138
				'id' => 'description',
139
				'name' => 'description',
140
				'rows' => 1,
141
				'value' => $category->description
142
			])
143
			->append('</li><li>')
144
			->label($this->_language->get('keywords'),
0 ignored issues
show
It seems like $this->_language->get('keywords') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
145
			[
146
				'for' => 'keywords'
147
			])
148
			->textarea(
149
			[
150
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
151
				'id' => 'keywords',
152
				'name' => 'keywords',
153
				'rows' => 1,
154
				'value' => $category->keywords
155
			])
156
			->append('</li><li>')
157
			->label($this->_language->get('robots'),
0 ignored issues
show
It seems like $this->_language->get('robots') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
158
			[
159
				'for' => 'robots'
160
			])
161
			->select($helperOption->getRobotArray(),
162
			[
163
				$category->robots
164
			],
165
			[
166
				'id' => 'robots',
167
				'name' => 'robots'
168
			])
169
			->append('</li></ul>')
170
171
			/* general */
172
173
			->radio(
174
			[
175
				'id' => self::class . '\General',
176
				'class' => 'rs-admin-fn-status-tab',
177
				'name' => self::class . '\Tab'
178
			])
179
			->label($this->_language->get('general'),
0 ignored issues
show
It seems like $this->_language->get('general') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
180
			[
181
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
182
				'for' => self::class . '\General'
183
			])
184
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
185
			->label($this->_language->get('language'),
0 ignored issues
show
It seems like $this->_language->get('language') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
186
			[
187
				'for' => 'language'
188
			])
189
			->select($helperOption->getLanguageArray(),
190
			[
191
				$category->language
192
			],
193
			[
194
				'id' => 'language',
195
				'name' => 'language'
196
			])
197
			->append('</li><li>')
198
			->label($this->_language->get('template'),
0 ignored issues
show
It seems like $this->_language->get('template') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
199
			[
200
				'for' => 'template'
201
			])
202
			->select($helperOption->getTemplateArray(),
203
			[
204
				$category->template
205
			],
206
			[
207
				'id' => 'template',
208
				'name' => 'template'
209
			])
210
			->append('</li><li>')
211
			->label($this->_language->get('category_sibling'),
0 ignored issues
show
It seems like $this->_language->get('category_sibling') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
212
			[
213
				'for' => 'sibling'
214
			])
215
			->select($helperOption->getSiblingForCategoryArray($category->id),
216
			[
217
				$category->sibling
218
			],
219
			[
220
				'id' => 'sibling',
221
				'name' => 'sibling'
222
			])
223
			->append('</li><li>')
224
			->label($this->_language->get('category_parent'),
0 ignored issues
show
It seems like $this->_language->get('category_parent') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
225
			[
226
				'for' => 'parent'
227
			])
228
			->select($helperOption->getParentForCategoryArray($category->id),
229
			[
230
				$category->parent
231
			],
232
			[
233
				'id' => 'parent',
234
				'name' => 'parent'
235
			])
236
			->append('</li></ul>')
237
238
			/* customize */
239
240
			->radio(
241
			[
242
				'id' => self::class . '\Customize',
243
				'class' => 'rs-admin-fn-status-tab',
244
				'name' => self::class . '\Tab'
245
			])
246
			->label($this->_language->get('customize'),
0 ignored issues
show
It seems like $this->_language->get('customize') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
247
			[
248
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
249
				'for' => self::class . '\Customize'
250
			])
251
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
252
			->label($this->_language->get('status'),
0 ignored issues
show
It seems like $this->_language->get('status') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
253
			[
254
				'for' => 'status'
255
			])
256
			->select($helperOption->getVisibleArray(),
257
			[
258
				$category->id ? $category->status : 1
259
			],
260
			[
261
				'id' => 'status',
262
				'name' => 'status'
263
			])
264
			->append('</li><li>')
265
			->label($this->_language->get('rank'),
0 ignored issues
show
It seems like $this->_language->get('rank') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
266
			[
267
				'for' => 'rank'
268
			])
269
			->number(
270
			[
271
				'id' => 'rank',
272
				'name' => 'rank',
273
				'value' => $category->id ? $category->rank : $categoryModel->query()->max('rank') + 1
274
			])
275
			->append('</li>');
276
		if ($this->_registry->get('groupsEdit'))
277
		{
278
			$formElement
279
				->append('<li>')
280
				->label($this->_language->get('access'),
0 ignored issues
show
It seems like $this->_language->get('access') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
281
				[
282
					'for' => 'access'
283
				])
284
				->select($helperOption->getGroupArray(),
285
				(array)json_decode($category->access),
286
				[
287
					'id' => 'access',
288
					'name' => 'access[]',
289
					'multiple' => 'multiple',
290
					'size' => count($helperOption->getGroupArray())
291
				])
292
				->append('</li>');
293
		}
294
		$formElement
295
			->append('<li>')
296
			->label($this->_language->get('date'),
0 ignored issues
show
It seems like $this->_language->get('date') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

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.

Loading history...
297
			[
298
				'for' => 'date'
299
			])
300
			->datetime(
301
			[
302
				'id' => 'date',
303
				'name' => 'date',
304
				'value' => $dater->formatField()
305
			])
306
			->append('</li></ul>')
307
			->hidden(
308
			[
309
				'name' => 'id',
310
				'value' => $category->id
311
			])
312
			->token()
313
			->append('<div class="rs-admin-wrapper-button">')
314
			->cancel();
315
		if ($category->id)
316
		{
317
			if ($this->_registry->get('categoriesDelete'))
318
			{
319
				$formElement->delete();
320
			}
321
			if ($this->_registry->get('categoriesEdit'))
322
			{
323
				$formElement->save();
324
			}
325
		}
326
		else if ($this->_registry->get('categoriesNew'))
327
		{
328
			$formElement->create();
329
		}
330
		$formElement->append('</div>');
331
332
		/* collect output */
333
334
		$output .= $titleElement . $formElement;
335
		$output .= Module\Hook::trigger('adminCategoryFormEnd');
336
		return $output;
337
	}
338
}
339