CategoryForm   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 316
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 10
dl 0
loc 316
ccs 148
cts 148
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C render() 0 303 12
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 function count;
9
use function json_decode;
10
11
/**
12
 * children class to create the category form
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category View
18
 * @author Henry Ruhs
19
 */
20
21
class CategoryForm extends ViewAbstract
22
{
23
	/**
24
	 * render the view
25
	 *
26
	 * @since 3.0.0
27
	 *
28
	 * @param int $categoryId identifier of the category
29
	 *
30
	 * @return string
31
	 */
32
33 4
	public function render(int $categoryId = null) : string
34
	{
35 4
		$output = Module\Hook::trigger('adminCategoryFormStart');
36 4
		$helperOption = new Helper\Option($this->_language);
37 4
		$categoryModel = new Admin\Model\Category();
38 4
		$category = $categoryModel->getById($categoryId);
39 4
		$dater = new Dater();
40 4
		$dater->init($category->date);
41
42
		/* html element */
43
44 4
		$titleElement = new Html\Element();
45
		$titleElement
46 4
			->init('h2',
47
			[
48 4
				'class' => 'rs-admin-title-content',
49
			])
50 4
			->text($category->title ? : $this->_language->get('category_new'));
51 4
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
52 4
		$formElement->init(
53
		[
54 4
			'form' =>
55
			[
56
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
57
			],
58
			'button' =>
59
			[
60
				'create' =>
61
				[
62
					'name' => self::class
63
				],
64
				'save' =>
65
				[
66
					'name' => self::class
67
				]
68
			],
69
			'link' =>
70
			[
71
				'cancel' =>
72
				[
73 4
					'href' => $this->_registry->get('categoriesEdit') && $this->_registry->get('categoriesDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/categories' : $this->_registry->get('parameterRoute') . 'admin'
74
				],
75
				'delete' =>
76
				[
77 4
					'href' => $category->id ? $this->_registry->get('parameterRoute') . 'admin/delete/categories/' . $category->id . '/' . $this->_registry->get('token') : null
78
				]
79
			]
80
		]);
81
82
		/* create the form */
83
84
		$formElement
85
86
			/* category */
87
88 4
			->radio(
89
			[
90 4
				'id' => self::class . '\Category',
91
				'class' => 'rs-admin-fn-status-tab',
92
				'name' => self::class . '\Tab',
93
				'checked' => 'checked'
94
			])
95 4
			->label($this->_language->get('category'),
0 ignored issues
show
Bug introduced by Henry Ruhs
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...
96
			[
97 4
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
98
				'for' => self::class . '\Category'
99
			])
100 4
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
101 4
			->label($this->_language->get('title'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
102
			[
103 4
				'for' => 'title'
104
			])
105 4
			->text(
106
			[
107 4
				'autofocus' => 'autofocus',
108 4
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
109 4
				'id' => 'title',
110 4
				'name' => 'title',
111 4
				'required' => 'required',
112 4
				'value' => $category->title
113
			])
114 4
			->append('</li><li>')
115 4
			->label($this->_language->get('alias'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
116
			[
117 4
				'for' => 'alias'
118
			])
119 4
			->text(
120
			[
121 4
				'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
122 4
				'id' => 'alias',
123 4
				'name' => 'alias',
124 4
				'pattern' => '[a-zA-Z0-9-]+',
125 4
				'required' => 'required',
126 4
				'value' => $category->alias
127
			])
128 4
			->append('</li><li>')
129 4
			->label($this->_language->get('description'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
130
			[
131 4
				'for' => 'description'
132
			])
133 4
			->textarea(
134
			[
135 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
136 4
				'id' => 'description',
137 4
				'name' => 'description',
138 4
				'rows' => 1,
139 4
				'value' => $category->description
140
			])
141 4
			->append('</li><li>')
142 4
			->label($this->_language->get('keywords'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
143
			[
144 4
				'for' => 'keywords'
145
			])
146 4
			->textarea(
147
			[
148 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
149 4
				'id' => 'keywords',
150 4
				'name' => 'keywords',
151 4
				'rows' => 1,
152 4
				'value' => $category->keywords
153
			])
154 4
			->append('</li><li>')
155 4
			->label($this->_language->get('robots'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
156
			[
157 4
				'for' => 'robots'
158
			])
159 4
			->select($helperOption->getRobotArray(),
160
			[
161 4
				$category->robots
162
			],
163
			[
164 4
				'id' => 'robots',
165
				'name' => 'robots'
166
			])
167 4
			->append('</li></ul>')
168
169
			/* general */
170
171 4
			->radio(
172
			[
173 4
				'id' => self::class . '\General',
174
				'class' => 'rs-admin-fn-status-tab',
175
				'name' => self::class . '\Tab'
176
			])
177 4
			->label($this->_language->get('general'),
0 ignored issues
show
Bug introduced by Henry Ruhs
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...
178
			[
179 4
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
180
				'for' => self::class . '\General'
181
			])
182 4
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
183 4
			->label($this->_language->get('language'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
184
			[
185 4
				'for' => 'language'
186
			])
187 4
			->select($helperOption->getLanguageArray(),
188
			[
189 4
				$category->language
190
			],
191
			[
192 4
				'id' => 'language',
193
				'name' => 'language'
194
			])
195 4
			->append('</li><li>')
196 4
			->label($this->_language->get('template'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
197
			[
198 4
				'for' => 'template'
199
			])
200 4
			->select($helperOption->getTemplateArray(),
201
			[
202 4
				$category->template
203
			],
204
			[
205 4
				'id' => 'template',
206
				'name' => 'template'
207
			])
208 4
			->append('</li><li>')
209 4
			->label($this->_language->get('category_sibling'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
210
			[
211 4
				'for' => 'sibling'
212
			])
213 4
			->select($helperOption->getSiblingForCategoryArray($category->id),
214
			[
215 4
				$category->sibling
216
			],
217
			[
218 4
				'id' => 'sibling',
219
				'name' => 'sibling'
220
			])
221 4
			->append('</li><li>')
222 4
			->label($this->_language->get('category_parent'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
223
			[
224 4
				'for' => 'parent'
225
			])
226 4
			->select($helperOption->getParentForCategoryArray($category->id),
227
			[
228 4
				$category->parent
229
			],
230
			[
231 4
				'id' => 'parent',
232
				'name' => 'parent'
233
			])
234 4
			->append('</li></ul>')
235
236
			/* customize */
237
238 4
			->radio(
239
			[
240 4
				'id' => self::class . '\Customize',
241
				'class' => 'rs-admin-fn-status-tab',
242
				'name' => self::class . '\Tab'
243
			])
244 4
			->label($this->_language->get('customize'),
0 ignored issues
show
Bug introduced by Henry Ruhs
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...
245
			[
246 4
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
247
				'for' => self::class . '\Customize'
248
			])
249 4
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
250 4
			->label($this->_language->get('status'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
251
			[
252 4
				'for' => 'status'
253
			])
254 4
			->select($helperOption->getVisibleArray(),
255
			[
256 4
				$category->id ? $category->status : 1
257
			],
258
			[
259 4
				'id' => 'status',
260
				'name' => 'status'
261
			])
262 4
			->append('</li><li>')
263 4
			->label($this->_language->get('rank'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
264
			[
265 4
				'for' => 'rank'
266
			])
267 4
			->number(
268
			[
269 4
				'id' => 'rank',
270 4
				'name' => 'rank',
271 4
				'value' => $category->id ? $category->rank : $categoryModel->query()->max('rank') + 1
272
			])
273 4
			->append('</li>');
274 4
		if ($this->_registry->get('groupsEdit'))
275
		{
276
			$formElement
277 4
				->append('<li>')
278 4
				->label($this->_language->get('access'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
279
				[
280 4
					'for' => 'access'
281
				])
282 4
				->select($helperOption->getGroupArray(),
283 4
				(array)json_decode($category->access),
284
				[
285 4
					'id' => 'access',
286 4
					'name' => 'access[]',
287 4
					'multiple' => 'multiple',
288 4
					'size' => count($helperOption->getGroupArray())
289
				])
290 4
				->append('</li>');
291
		}
292
		$formElement
293 4
			->append('<li>')
294 4
			->label($this->_language->get('date'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
295
			[
296 4
				'for' => 'date'
297
			])
298 4
			->datetime(
299
			[
300 4
				'id' => 'date',
301 4
				'name' => 'date',
302 4
				'value' => $dater->formatField()
303
			])
304 4
			->append('</li></ul>')
305 4
			->hidden(
306
			[
307 4
				'name' => 'id',
308 4
				'value' => $category->id
309
			])
310 4
			->token()
311 4
			->append('<div class="rs-admin-wrapper-button">')
312 4
			->cancel();
313 4
		if ($category->id)
314
		{
315 2
			if ($this->_registry->get('categoriesDelete'))
316
			{
317 1
				$formElement->delete();
318
			}
319 2
			if ($this->_registry->get('categoriesEdit'))
320
			{
321 2
				$formElement->save();
322
			}
323
		}
324 2
		else if ($this->_registry->get('categoriesNew'))
325
		{
326 1
			$formElement->create();
327
		}
328 4
		$formElement->append('</div>');
329
330
		/* collect output */
331
332 4
		$output .= $titleElement . $formElement;
333 4
		$output .= Module\Hook::trigger('adminCategoryFormEnd');
334 4
		return $output;
335
	}
336
}
337