Completed
Push — master ( 4d87e8...6f96cd )
by Henry
06:30
created

includes/Admin/View/ExtraForm.php (15 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 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 4
35
	public function render(int $extraId = null) : string
36 4
	{
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
		$aliasValidator = new Validator\Alias();
42
		$dater = new Dater();
43
		$dater->init($extra->date);
44
45 4
		/* html element */
46
47 4
		$titleElement = new Html\Element();
48
		$titleElement
49 4
			->init('h2',
50
			[
51 4
				'class' => 'rs-admin-title-content',
52 4
			])
53 4
			->text($extra->title ? : $this->_language->get('extra_new'));
54
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
55 4
		$formElement->init(
56
		[
57
			'form' =>
58
			[
59
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
60
			],
61
			'button' =>
62
			[
63
				'create' =>
64
				[
65
					'name' => self::class
66
				],
67
				'save' =>
68
				[
69
					'name' => self::class
70
				]
71
			],
72
			'link' =>
73
			[
74 4
				'cancel' =>
75
				[
76
					'href' => $this->_registry->get('extrasEdit') && $this->_registry->get('extrasDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/extras' : $this->_registry->get('parameterRoute') . 'admin'
77
				],
78 4
				'delete' =>
79
				[
80
					'href' => $extra->id ? $this->_registry->get('parameterRoute') . 'admin/delete/extras/' . $extra->id . '/' . $this->_registry->get('token') : null
81
				]
82
			]
83
		]);
84
85
		/* create the form */
86
87
		$formElement
88
89 4
			/* extra */
90
91 4
			->radio(
92
			[
93
				'id' => self::class . '\Extra',
94
				'class' => 'rs-admin-fn-status-tab',
95
				'name' => self::class . '\Tab',
96 4
				'checked' => 'checked'
97
			])
98 4
			->label($this->_language->get('extra'),
0 ignored issues
show
It seems like $this->_language->get('extra') 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...
99
			[
100
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
101 4
				'for' => self::class . '\Extra'
102 4
			])
103
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
104 4
			->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...
105
			[
106 4
				'for' => 'title'
107
			])
108 4
			->text(
109 4
			[
110 4
				'autofocus' => 'autofocus',
111 4
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
112 4
				'id' => 'title',
113 4
				'name' => 'title',
114
				'required' => 'required',
115 4
				'value' => $extra->title
116 4
			])
117
			->append('</li><li>')
118 4
			->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...
119
			[
120 4
				'for' => 'alias'
121
			])
122 4
			->text(
123 4
			[
124 4
				'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
125 4
				'id' => 'alias',
126 4
				'name' => 'alias',
127 4
				'pattern' => $aliasValidator->getFormPattern(),
128
				'required' => 'required',
129 4
				'value' => $extra->alias
130 4
			])
131
			->append('</li><li>')
132 4
			->label($this->_language->get('text'),
0 ignored issues
show
It seems like $this->_language->get('text') 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...
133
			[
134 4
				'for' => 'text'
135
			])
136 4
			->textarea(
137 4
			[
138 4
				'class' => 'rs-admin-js-editor rs-admin-js-resize rs-admin-field-textarea',
139 4
				'id' => 'text',
140 4
				'name' => 'text',
141
				'required' => 'required',
142 4
				'value' => htmlspecialchars($extra->text, ENT_QUOTES)
143
			])
144
			->append('</li></ul>')
145
146 4
			/* general */
147
148 4
			->radio(
149
			[
150
				'id' => self::class . '\General',
151
				'class' => 'rs-admin-fn-status-tab',
152 4
				'name' => self::class . '\Tab'
153
			])
154 4
			->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...
155
			[
156
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
157 4
				'for' => self::class . '\General'
158 4
			])
159
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
160 4
			->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...
161
			[
162 4
				'for' => 'language'
163
			])
164 4
			->select($helperOption->getLanguageArray(),
165
			[
166
				$extra->language
167 4
			],
168
			[
169
				'id' => 'language',
170 4
				'name' => 'language'
171 4
			])
172
			->append('</li><li>')
173 4
			->label($this->_language->get('extra_sibling'),
0 ignored issues
show
It seems like $this->_language->get('extra_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...
174
			[
175 4
				'for' => 'sibling'
176
			])
177 4
			->select($helperOption->getSiblingForExtraArray($extra->id),
178
			[
179
				$extra->sibling
180 4
			],
181
			[
182
				'id' => 'sibling',
183 4
				'name' => 'sibling'
184 4
			])
185
			->append('</li><li>')
186 4
			->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...
187
			[
188 4
				'for' => 'category'
189
			])
190 4
			->select($helperOption->getCategoryArray(),
191
			[
192
				$extra->category
193 4
			],
194
			[
195
				'id' => 'category',
196 4
				'name' => 'category'
197 4
			])
198
			->append('</li><li>')
199 4
			->label($this->_language->get('article'),
0 ignored issues
show
It seems like $this->_language->get('article') 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...
200
			[
201 4
				'for' => 'article'
202
			])
203 4
			->select($helperOption->getArticleArray(),
204
			[
205
				$extra->article
206 4
			],
207
			[
208
				'id' => 'article',
209 4
				'name' => 'article'
210
			])
211
			->append('</li></ul>')
212
213 4
			/* customize */
214
215 4
			->radio(
216
			[
217
				'id' => self::class . '\Customize',
218
				'class' => 'rs-admin-fn-status-tab',
219 4
				'name' => self::class . '\Tab'
220
			])
221 4
			->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...
222
			[
223
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
224 4
				'for' => self::class . '\Customize'
225 4
			])
226
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
227 4
			->label($this->_language->get('headline'),
0 ignored issues
show
It seems like $this->_language->get('headline') 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...
228
			[
229 4
				'for' => 'headline'
230
			])
231 4
			->select($helperOption->getToggleArray(),
232
			[
233
				$extra->id ? $extra->headline : 1
234 4
			],
235
			[
236
				'id' => 'headline',
237 4
				'name' => 'headline'
238 4
			])
239
			->append('</li><li>')
240 4
			->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...
241
			[
242 4
				'for' => 'status'
243
			])
244 4
			->select($helperOption->getVisibleArray(),
245
			[
246
				$extra->id ? $extra->status : 1
247 4
			],
248
			[
249
				'id' => 'status',
250 4
				'name' => 'status'
251 4
			])
252
			->append('</li><li>')
253 4
			->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...
254
			[
255 4
				'for' => 'rank'
256
			])
257 4
			->number(
258 4
			[
259 4
				'id' => 'rank',
260
				'name' => 'rank',
261 4
				'value' => $extra->id ? $extra->rank : $extraModel->query()->max('rank') + 1
262 4
			])
263
			->append('</li>');
264
		if ($this->_registry->get('groupsEdit'))
265 4
		{
266 4
			$formElement
267
				->append('<li>')
268 4
				->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...
269
				[
270 4
					'for' => 'access'
271 4
				])
272
				->select($helperOption->getGroupArray(),
273 4
				(array)json_decode($extra->access),
274 4
				[
275 4
					'id' => 'access',
276 4
					'name' => 'access[]',
277
					'multiple' => 'multiple',
278 4
					'size' => count($helperOption->getGroupArray())
279
				])
280
				->append('</li>');
281 4
		}
282 4
		$formElement
283
			->append('<li>')
284 4
			->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...
285
			[
286 4
				'for' => 'date'
287
			])
288 4
			->datetime(
289 4
			[
290 4
				'id' => 'date',
291
				'name' => 'date',
292 4
				'value' => $dater->formatField()
293 4
			])
294
			->append('</li></ul>')
295 4
			->hidden(
296 4
			[
297
				'name' => 'id',
298 4
				'value' => $extra->id
299 4
			])
300 4
			->token()
301 4
			->append('<div class="rs-admin-wrapper-button">')
302
			->cancel();
303 2
		if ($extra->id)
304
		{
305 1
			if ($this->_registry->get('extrasDelete'))
306
			{
307 2
				$formElement->delete();
308
			}
309 2
			if ($this->_registry->get('extrasEdit'))
310
			{
311
				$formElement->save();
312 2
			}
313
		}
314 1
		else if ($this->_registry->get('extrasNew'))
315
		{
316 4
			$formElement->create();
317
		}
318
		$formElement->append('</div>');
319
320 4
		/* collect output */
321 4
322 4
		$output .= $titleElement . $formElement;
323
		$output .= Module\Hook::trigger('adminExtraFormEnd');
324
		return $output;
325
	}
326
}
327