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

includes/Admin/View/ArticleForm.php (20 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 article form
15
 *
16
 * @since 3.0.0
17
 *
18
 * @package Redaxscript
19
 * @category View
20
 * @author Henry Ruhs
21
 */
22
23
class ArticleForm extends ViewAbstract
24
{
25
	/**
26
	 * render the view
27
	 *
28
	 * @since 3.0.0
29
	 *
30
	 * @param int $articleId identifier of the article
31
	 *
32
	 * @return string
33
	 */
34 4
35
	public function render(int $articleId = null) : string
36 4
	{
37 4
		$output = Module\Hook::trigger('adminArticleFormStart');
38 4
		$helperOption = new Helper\Option($this->_language);
39 4
		$articleModel = new Admin\Model\Article();
40 4
		$article = $articleModel->getById($articleId);
41 4
		$aliasValidator = new Validator\Alias();
42
		$dater = new Dater();
43
		$dater->init($article->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($article->title ? : $this->_language->get('article_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('articlesEdit') && $this->_registry->get('articlesDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/articles' : $this->_registry->get('parameterRoute') . 'admin'
77
				],
78 4
				'delete' =>
79
				[
80
					'href' => $article->id ? $this->_registry->get('parameterRoute') . 'admin/delete/articles/' . $article->id . '/' . $this->_registry->get('token') : null
81
				]
82
			]
83
		]);
84
85
		/* create the form */
86
87
		$formElement
88
89 4
			/* article */
90
91 4
			->radio(
92
			[
93
				'id' => self::class . '\Article',
94
				'class' => 'rs-admin-fn-status-tab',
95
				'name' => self::class . '\Tab',
96 4
				'checked' => 'checked'
97
			])
98 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...
99
			[
100
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
101 4
				'for' => self::class . '\Article'
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' => $article->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' => $article->alias
130 4
			])
131
			->append('</li><li>')
132 4
			->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...
133
			[
134 4
				'for' => 'description'
135
			])
136 4
			->textarea(
137 4
			[
138 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
139 4
				'id' => 'description',
140 4
				'name' => 'description',
141
				'rows' => 1,
142 4
				'value' => $article->description
143 4
			])
144
			->append('</li><li>')
145 4
			->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...
146
			[
147 4
				'for' => 'keywords'
148
			])
149 4
			->textarea(
150 4
			[
151 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
152 4
				'id' => 'keywords',
153 4
				'name' => 'keywords',
154
				'rows' => 1,
155 4
				'value' => $article->keywords
156 4
			])
157
			->append('</li><li>')
158 4
			->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...
159
			[
160 4
				'for' => 'robots'
161
			])
162 4
			->select($helperOption->getRobotArray(),
163
			[
164
				$article->robots
165 4
			],
166
			[
167
				'id' => 'robots',
168 4
				'name' => 'robots'
169 4
			])
170
			->append('</li><li>')
171 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...
172
			[
173 4
				'for' => 'text'
174
			])
175 4
			->textarea(
176 4
			[
177 4
				'class' => 'rs-admin-js-editor rs-admin-js-resize rs-admin-field-textarea',
178 4
				'id' => 'text',
179 4
				'name' => 'text',
180
				'required' => 'required',
181 4
				'value' => htmlspecialchars($article->text, ENT_QUOTES)
182
			])
183
			->append('</li></ul>')
184
185 4
			/* general */
186
187 4
			->radio(
188
			[
189
				'id' => self::class . '\General',
190
				'class' => 'rs-admin-fn-status-tab',
191 4
				'name' => self::class . '\Tab'
192
			])
193 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...
194
			[
195
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
196 4
				'for' => self::class . '\General'
197 4
			])
198
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
199 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...
200
			[
201 4
				'for' => 'language'
202
			])
203 4
			->select($helperOption->getLanguageArray(),
204
			[
205
				$article->language
206 4
			],
207
			[
208
				'id' => 'language',
209 4
				'name' => 'language'
210 4
			])
211
			->append('</li><li>')
212 4
			->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...
213
			[
214 4
				'for' => 'template'
215
			])
216 4
			->select($helperOption->getTemplateArray(),
217
			[
218
				$article->template
219 4
			],
220
			[
221
				'id' => 'template',
222 4
				'name' => 'template'
223 4
			])
224
			->append('</li><li>')
225 4
			->label($this->_language->get('article_sibling'),
0 ignored issues
show
It seems like $this->_language->get('article_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...
226
			[
227 4
				'for' => 'sibling'
228
			])
229 4
			->select($helperOption->getSiblingForArticleArray($article->id),
230
			[
231
				$article->sibling
232 4
			],
233
			[
234
				'id' => 'sibling',
235 4
				'name' => 'sibling'
236 4
			])
237
			->append('</li><li>')
238 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...
239
			[
240 4
				'for' => 'category'
241
			])
242 4
			->select($helperOption->getCategoryArray(),
243
			[
244
				$article->category
245 4
			],
246
			[
247
				'id' => 'category',
248 4
				'name' => 'category'
249
			])
250
			->append('</li></ul>')
251
252 4
			/* customize */
253
254 4
			->radio(
255
			[
256
				'id' => self::class . '\Customize',
257
				'class' => 'rs-admin-fn-status-tab',
258 4
				'name' => self::class . '\Tab'
259
			])
260 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...
261
			[
262
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
263 4
				'for' => self::class . '\Customize'
264 4
			])
265
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
266 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...
267
			[
268 4
				'for' => 'headline'
269
			])
270 4
			->select($helperOption->getToggleArray(),
271
			[
272
				$article->id ? $article->headline : 1
273 4
			],
274
			[
275
				'id' => 'headline',
276 4
				'name' => 'headline'
277 4
			])
278
			->append('</li><li>')
279 4
			->label($this->_language->get('byline'),
0 ignored issues
show
It seems like $this->_language->get('byline') 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...
280
			[
281 4
				'for' => 'byline'
282
			])
283 4
			->select($helperOption->getToggleArray(),
284
			[
285
				$article->id ? $article->byline : 1
286 4
			],
287
			[
288
				'id' => 'byline',
289 4
				'name' => 'byline'
290 4
			])
291
			->append('</li><li>')
292 4
			->label($this->_language->get('comments'),
0 ignored issues
show
It seems like $this->_language->get('comments') 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...
293
			[
294 4
				'for' => 'comments'
295
			])
296 4
			->select($helperOption->getToggleArray(),
297
			[
298
				$article->comments
299 4
			],
300
			[
301
				'id' => 'comments',
302 4
				'name' => 'comments'
303 4
			])
304
			->append('</li><li>')
305 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...
306
			[
307 4
				'for' => 'status'
308
			])
309 4
			->select($helperOption->getVisibleArray(),
310
			[
311
				$article->id ? $article->status : 1
312 4
			],
313
			[
314
				'id' => 'status',
315 4
				'name' => 'status'
316 4
			])
317
			->append('</li><li>')
318 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...
319
			[
320 4
				'for' => 'rank'
321
			])
322 4
			->number(
323 4
			[
324 4
				'id' => 'rank',
325
				'name' => 'rank',
326 4
				'value' => $article->id ? $article->rank : $articleModel->query()->max('rank') + 1
327 4
			])
328
			->append('</li>');
329
		if ($this->_registry->get('groupsEdit'))
330 1
		{
331 1
			$formElement
332
				->append('<li>')
333 1
				->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...
334
				[
335 1
					'for' => 'access'
336 1
				])
337
				->select($helperOption->getGroupArray(),
338 1
				(array)json_decode($article->access),
339 1
				[
340 1
					'id' => 'access',
341 1
					'name' => 'access[]',
342
					'multiple' => 'multiple',
343 1
					'size' => count($helperOption->getGroupArray())
344
				])
345
				->append('</li>');
346 4
		}
347 4
		$formElement
348
			->append('<li>')
349 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...
350
			[
351 4
				'for' => 'date'
352
			])
353 4
			->datetime(
354 4
			[
355 4
				'id' => 'date',
356
				'name' => 'date',
357 4
				'value' => $dater->formatField()
358 4
			])
359
			->append('</li></ul>')
360 4
			->hidden(
361 4
			[
362
				'name' => 'id',
363 4
				'value' => $article->id
364 4
			])
365 4
			->token()
366 4
			->append('<div class="rs-admin-wrapper-button">')
367
			->cancel();
368 2
		if ($article->id)
369
		{
370 1
			if ($this->_registry->get('articlesDelete'))
371
			{
372 2
				$formElement->delete();
373
			}
374 2
			if ($this->_registry->get('articlesEdit'))
375
			{
376
				$formElement->save();
377 2
			}
378
		}
379 1
		else if ($this->_registry->get('articlesNew'))
380
		{
381 4
			$formElement->create();
382
		}
383
		$formElement->append('</div>');
384
385 4
		/* collect output */
386 4
387 4
		$output .= $titleElement . $formElement;
388
		$output .= Module\Hook::trigger('adminArticleFormEnd');
389
		return $output;
390
	}
391
}
392