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