Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

includes/Admin/View/ArticleForm.php (20 issues)

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