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

includes/Admin/View/ModuleForm.php (6 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\Filesystem;
6
use Redaxscript\Html;
7
use Redaxscript\Module;
8
use function count;
9
use function is_array;
10
use function json_decode;
11
use function pathinfo;
12
13
/**
14
 * children class to create the module form
15
 *
16
 * @since 3.0.0
17
 *
18
 * @package Redaxscript
19
 * @category View
20
 * @author Henry Ruhs
21
 */
22
23
class ModuleForm extends ViewAbstract
24
{
25
	/**
26
	 * render the view
27
	 *
28
	 * @since 3.0.0
29
	 *
30
	 * @param int $moduleId identifier of the module
31
	 *
32
	 * @return string
33
	 */
34
35 2
	public function render(int $moduleId = null) : string
36
	{
37 2
		$output = Module\Hook::trigger('adminModuleFormStart');
38 2
		$moduleModel = new Admin\Model\Module();
39 2
		$module = $moduleModel->getById($moduleId);
40 2
		$helperOption = new Helper\Option($this->_language);
41
42
		/* html element */
43
44 2
		$titleElement = new Html\Element();
45
		$titleElement
46 2
			->init('h2',
47
			[
48 2
				'class' => 'rs-admin-title-content',
49
			])
50 2
			->text($module->name);
51 2
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
52 2
		$formElement->init(
53
		[
54 2
			'form' =>
55
			[
56
				'class' => 'rs-admin-js-validate rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
57
			],
58
			'button' =>
59
			[
60
				'save' =>
61
				[
62
					'name' => self::class
63
				]
64
			],
65
			'link' =>
66
			[
67
				'cancel' =>
68
				[
69 2
					'href' => $this->_registry->get('modulesEdit') && $this->_registry->get('modulesUninstall') ? $this->_registry->get('parameterRoute') . 'admin/view/modules' : $this->_registry->get('parameterRoute') . 'admin'
70
				],
71
				'uninstall' =>
72
				[
73 2
					'href' => $module->alias ? $this->_registry->get('parameterRoute') . 'admin/uninstall/modules/' . $module->alias . '/' . $this->_registry->get('token') : null
74
				]
75
			]
76
		]);
77
78
		/* docs filesystem */
79
80 2
		$docsFilesystem = new Filesystem\File();
81 2
		$docsFilesystem->init('modules' . DIRECTORY_SEPARATOR . $module->alias . DIRECTORY_SEPARATOR . 'docs');
82 2
		$docsFilesystemArray = $docsFilesystem->getSortArray();
83
84
		/* create the form */
85
86
		$formElement
87
88
			/* module */
89
90 2
			->radio(
91
			[
92 2
				'id' => self::class . '\Module',
93
				'class' => 'rs-admin-fn-status-tab',
94
				'name' => self::class . '\Tab',
95
				'checked' => 'checked'
96
			])
97 2
			->label($this->_language->get('module'),
0 ignored issues
show
It seems like $this->_language->get('module') 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...
98
			[
99 2
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
100
				'for' => self::class . '\Module'
101
			])
102 2
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
103 2
			->label($this->_language->get('name'),
0 ignored issues
show
It seems like $this->_language->get('name') 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...
104
			[
105 2
				'for' => 'name'
106
			])
107 2
			->text(
108
			[
109 2
				'autofocus' => 'autofocus',
110 2
				'id' => 'name',
111 2
				'name' => 'name',
112 2
				'required' => 'required',
113 2
				'value' => $module->name
114
			])
115 2
			->append('</li><li>')
116 2
			->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...
117
			[
118 2
				'for' => 'description'
119
			])
120 2
			->textarea(
121
			[
122 2
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
123 2
				'id' => 'description',
124 2
				'name' => 'description',
125 2
				'rows' => 1,
126 2
				'value' => $module->description
127
			])
128 2
			->append('</li></ul>');
129 2
		if (is_array($docsFilesystemArray))
130
		{
131 2
			foreach ($docsFilesystemArray as $file)
132
			{
133 2
				$fileName = pathinfo($file, PATHINFO_FILENAME);
134
				$formElement
135
136
					/* doc */
137
138 2
					->radio(
139
					[
140 2
						'id' => self::class . '\Doc\\' . $fileName,
141 2
						'class' => 'rs-admin-fn-status-tab',
142
						'name' => self::class . '\Tab'
143
					])
144 2
					->label($fileName,
145
					[
146 2
						'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
147 2
						'for' => self::class . '\Doc\\' . $fileName,
148
					])
149 2
					->append('<div class="rs-admin-fn-content-tab rs-admin-box-tab">')
150 2
					->append($docsFilesystem->renderFile($file))
151 2
					->append('</div>');
152
			}
153
		}
154
		$formElement
155
156
			/* customize */
157
158 2
			->radio(
159
			[
160 2
				'id' => self::class . '\Customize',
161
				'class' => 'rs-admin-fn-status-tab',
162
				'name' => self::class . '\Tab'
163
			])
164 2
			->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...
165
			[
166 2
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
167
				'for' => self::class . '\Customize'
168
			])
169 2
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
170 2
			->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...
171
			[
172 2
				'for' => 'status'
173
			])
174 2
			->select($helperOption->getToggleArray(),
175
			[
176 2
				$module->status
177
			],
178
			[
179 2
				'id' => 'status',
180
				'name' => 'status'
181
			])
182 2
			->append('</li>');
183 2
		if ($this->_registry->get('groupsEdit'))
184
		{
185
			$formElement
186
				->append('<li>')
187
				->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...
188
				[
189
					'for' => 'access'
190
				])
191
				->select($helperOption->getGroupArray(),
192
				(array)json_decode($module->access),
193
				[
194
					'id' => 'access',
195
					'name' => 'access[]',
196
					'multiple' => 'multiple',
197
					'size' => count($helperOption->getGroupArray())
198
				])
199
				->append('</li>');
200
		}
201
		$formElement
202 2
			->append('</ul>')
203 2
			->hidden(
204
			[
205 2
				'name' => 'id',
206 2
				'value' => $module->id
207
			])
208 2
			->token()
209 2
			->append('<div class="rs-admin-wrapper-button">')
210 2
			->cancel();
211 2
		if ($this->_registry->get('modulesUninstall'))
212
		{
213 1
			$formElement->uninstall();
214
		}
215 2
		if ($this->_registry->get('modulesEdit'))
216
		{
217 1
			$formElement->save();
218
		}
219 2
		$formElement->append('</div>');
220
221
		/* collect output */
222
223 2
		$output .= $titleElement . $formElement;
224 2
		$output .= Module\Hook::trigger('adminModuleFormEnd');
225 2
		return $output;
226
	}
227
}
228