Completed
Push — master ( 9027b3...432a29 )
by Henry
12:53 queued 02:53
created

includes/Admin/View/ModuleForm.php (1 issue)

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\Html;
6
use Redaxscript\Module;
7
use Redaxscript\Validator;
8
use function count;
9
use function json_decode;
10
11
/**
12
 * children class to create the module form
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category View
18
 * @author Henry Ruhs
19
 */
20
21
class ModuleForm extends ViewAbstract
22
{
23
	/**
24
	 * render the view
25
	 *
26
	 * @since 3.0.0
27
	 *
28
	 * @param int $moduleId identifier of the module
29
	 *
30
	 * @return string
31
	 */
32
33 2
	public function render(int $moduleId = null) : string
34
	{
35 2
		$output = Module\Hook::trigger('adminModuleFormStart');
36 2
		$moduleModel = new Admin\Model\Module();
37 2
		$module = $moduleModel->getById($moduleId);
38 2
		$helperOption = new Helper\Option($this->_language);
39 2
		$nameValidator = new Validator\Name();
40
41
		/* html element */
42
43 2
		$titleElement = new Html\Element();
44
		$titleElement
45 2
			->init('h2',
46
			[
47 2
				'class' => 'rs-admin-title-content',
48
			])
49 2
			->text($module?->name);
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR
Loading history...
50 2
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
51 2
		$formElement->init(
52
		[
53
			'form' =>
54
			[
55 2
				'class' => 'rs-admin-js-validate rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default rs-admin-form-module'
56
			],
57
			'button' =>
58
			[
59
				'save' =>
60
				[
61
					'name' => self::class
62
				]
63
			],
64
			'link' =>
65
			[
66
				'cancel' =>
67
				[
68 2
					'href' => $this->_registry->get('modulesEdit') && $this->_registry->get('modulesUninstall') ? $this->_registry->get('parameterRoute') . 'admin/view/modules' : $this->_registry->get('parameterRoute') . 'admin'
69
				],
70
				'uninstall' =>
71
				[
72 2
					'href' => $module?->alias ? $this->_registry->get('parameterRoute') . 'admin/uninstall/modules/' . $module?->alias . '/' . $this->_registry->get('token') : null
73
				]
74
			]
75
		]);
76
77
		/* create the form */
78
79
		$formElement
80
81
			/* module */
82
83 2
			->radio(
84
			[
85 2
				'id' => self::class . '\Module',
86
				'class' => 'rs-admin-fn-status-tab',
87
				'name' => self::class . '\Tab',
88
				'checked' => 'checked'
89
			])
90 2
			->label($this->_language->get('module'),
91
			[
92 2
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
93
				'for' => self::class . '\Module'
94
			])
95 2
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
96 2
			->label($this->_language->get('name'),
97
			[
98 2
				'for' => 'name'
99
			])
100 2
			->text(
101
			[
102 2
				'autofocus' => 'autofocus',
103 2
				'id' => 'name',
104 2
				'name' => 'name',
105 2
				'pattern' => $nameValidator->getPattern(),
106 2
				'required' => 'required',
107 2
				'value' => $module?->name
108
			])
109 2
			->append('</li><li>')
110 2
			->label($this->_language->get('description'),
111
			[
112 2
				'for' => 'description'
113
			])
114 2
			->textarea(
115
			[
116 2
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
117 2
				'id' => 'description',
118 2
				'name' => 'description',
119 2
				'rows' => 1,
120 2
				'value' => $module?->description
121
			])
122 2
			->append('</li></ul>')
123
124
			/* customize */
125
126 2
			->radio(
127
			[
128 2
				'id' => self::class . '\Customize',
129
				'class' => 'rs-admin-fn-status-tab',
130
				'name' => self::class . '\Tab'
131
			])
132 2
			->label($this->_language->get('customize'),
133
			[
134 2
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
135
				'for' => self::class . '\Customize'
136
			])
137 2
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
138 2
			->label($this->_language->get('status'),
139
			[
140 2
				'for' => 'status'
141
			])
142 2
			->checkbox($module?->status ?
143
			[
144 2
				'id' => 'status',
145
				'class' => 'rs-admin-fn-status-switch',
146
				'name' => 'status',
147
				'checked' => 'checked'
148
			] :
149
			[
150 2
				'id' => 'status',
151
				'class' => 'rs-admin-fn-status-switch',
152
				'name' => 'status'
153
			])
154 2
			->label(null,
155
			[
156 2
				'class' => 'rs-admin-label-switch',
157 2
				'for' => 'status',
158 2
				'data-on' => $this->_language->get('enable'),
159 2
				'data-off' => $this->_language->get('disable')
160
			])
161 2
			->append('</li>');
162 2
		if ($this->_registry->get('groupsEdit'))
163
		{
164
			$formElement
165
				->append('<li>')
166
				->label($this->_language->get('access'),
167
				[
168
					'for' => 'access'
169
				])
170
				->select($helperOption->getGroupArray(),
171
				(array)json_decode($module?->access),
172
				[
173
					'id' => 'access',
174
					'name' => 'access[]',
175
					'multiple' => 'multiple',
176
					'size' => count($helperOption->getGroupArray())
177
				])
178
				->append('</li>');
179
		}
180
		$formElement
181 2
			->append('</ul>')
182 2
			->hidden(
183
			[
184 2
				'name' => 'id',
185 2
				'value' => $module?->id
186
			])
187 2
			->token()
188 2
			->append('<div class="rs-admin-wrapper-button">')
189 2
			->cancel();
190 2
		if ($this->_registry->get('modulesUninstall'))
191
		{
192 1
			$formElement->uninstall();
193
		}
194 2
		if ($this->_registry->get('modulesEdit'))
195
		{
196 1
			$formElement->save();
197
		}
198 2
		$formElement->append('</div>');
199
200
		/* collect output */
201
202 2
		$output .= $titleElement . $formElement;
203 2
		$output .= Module\Hook::trigger('adminModuleFormEnd');
204 2
		return $output;
205
	}
206
}
207