4
4
* @file
5
5
* OSInet Quality Assurance module for Drupal.
6
6
*
7
- * @copyright Copyright (C) 2005-2018 Frederic G. MARAND for Ouest Systèmes Informatiques (OSInet)
7
+ * @copyright Copyright (C) 2005-2018 Frederic G. MARAND for Ouest Systèmes
8
+ * Informatiques (OSInet)
8
9
*
9
10
* @since DRUPAL-4-6
10
11
*
11
- * @license Licensed under the disjunction of the CeCILL, version 2 and General Public License version 2 and later
12
+ * @license Licensed under the disjunction of the CeCILL, version 2 and General
13
+ * Public License version 2 and later
12
14
*
13
15
* License note: QA is distributed by OSInet to its customers under the
14
16
* CeCILL 2.0 license. OSInet support services only apply to the module
21
23
* are abided by, the module distributor in that case being the
22
24
* drupal.org organization or the downstream distributor, not OSInet.
23
25
*/
26
+
27
+ use Drupal\Component\Utility\Xss;
28
+ use Drupal\Core\Url;
24
29
use Drupal\qa\Variable\Variable;
30
+ use Symfony\Component\HttpFoundation\RedirectResponse;
25
31
26
32
/**
27
33
* Page callback for qa/dependencies
@@ -33,7 +39,7 @@ use Drupal\qa\Variable\Variable;
33
39
*/
34
40
function qa_page_dependencies() {
35
41
/** @var \Drupal\qa\Dependencies $qaDep */
36
- $qaDep = \ Drupal::service('qa.dependencies');
42
+ $qaDep = Drupal::service('qa.dependencies');
37
43
$G = $qaDep->build();
38
44
// passed by reference: cannot pass a function return
39
45
return graphviz_filter_render($G);
@@ -49,14 +55,16 @@ function qa_page_dependencies() {
49
55
function qa_report_finished($success, $results, $operations) {
50
56
unset($results['#message']);
51
57
if ($success) {
52
- $message = format_plural(count($results), 'One control pass ran.', '@count control passes ran.');
58
+ $message = Drupal::translation()
59
+ ->formatPlural(count($results), 'One control pass ran.',
60
+ '@count control passes ran.');
53
61
}
54
62
else {
55
63
$message = t('Finished with an error.');
56
64
}
57
65
drupal_set_message($message);
58
66
$_SESSION['qa_results'] = $results;
59
- drupal_goto('admin/reports/qa/ results');
67
+ return new RedirectResponse(Url::fromRoute('qa.reports. results') );
60
68
}
61
69
62
70
/**
@@ -66,37 +74,41 @@ function qa_report_finished($success, $results, $operations) {
66
74
*/
67
75
function qa_report_results() {
68
76
if (empty($_SESSION['qa_results'])) {
69
- drupal_goto('admin/reports/qa' );
77
+ return new RedirectResponse(Url::fromRoute('qa.reports') );
70
78
}
71
79
// Work around incomplete classes
72
80
$results = unserialize(serialize($_SESSION['qa_results']));
73
81
74
- $header = array(
82
+ $header = [
75
83
t('Control'),
76
84
t('Status'),
77
85
t('Results'),
78
- );
79
- $data = array();
86
+ ];
87
+ $data = [];
88
+ $r = Drupal::service('renderer');
80
89
foreach ($results as $pass) {
81
90
$control = $pass->control;
82
- $data[] = array(
91
+ $data[] = [
83
92
$control->title,
84
93
$pass->status
85
- ? theme('image', array(
86
- 'path' => 'misc/watchdog-ok.png',
87
- 'alt' => t('OK'),
88
- ))
89
- : theme('image', array(
90
- 'path' => 'misc/watchdog-error.png',
91
- 'alt' => t('Error'),
92
- )),
94
+ ? $r->render([
95
+ '#theme' => 'image',
96
+ '#path' => 'misc/watchdog-ok.png',
97
+ '#alt' => t('OK'),
98
+ ])
99
+ : $r->render([
100
+ '#theme' => 'image',
101
+ '#path' => 'misc/watchdog-error.png',
102
+ '#alt' => t('Error'),
103
+ ]),
93
104
$pass->result,
94
- ) ;
105
+ ] ;
95
106
}
96
- $ret = theme('table', [
97
- 'header' => $header,
98
- 'rows' => $data,
99
- 'attributes' => [
107
+ $ret = $r->render([
108
+ '#theme' => 'table',
109
+ '#header' => $header,
110
+ '#rows' => $data,
111
+ '#attributes' => [
100
112
'id' => 'qa-results',
101
113
],
102
114
'#attached' => ['library' => ['qa/results']],
@@ -111,19 +123,20 @@ function qa_report_results() {
111
123
* @return array
112
124
*/
113
125
function qa_report_form($form, $form_state) {
114
- $form = array() ;
126
+ $form = [] ;
115
127
$base = drupal_get_path('module', 'qa');
116
128
$packages = Exportable::getClasses($base, 'Drupal\qa\BasePackage');
117
129
ksort($packages);
118
130
foreach ($packages as $package_name => $package) {
119
131
$collapsed = TRUE;
120
- $form[$package_name] = array(
132
+ $form[$package_name] = [
121
133
'#type' => 'fieldset',
122
- '#title' => filter_xss_admin ($package->title),
123
- '#description' => filter_xss_admin ($package->description),
134
+ '#title' => Xss::filterAdmin ($package->title),
135
+ '#description' => Xss::filterAdmin ($package->description),
124
136
'#collapsible' => TRUE,
125
- );
126
- $controls = $package->getClasses($package->dir, 'Drupal\qa\Plugin\Qa\Control\BaseControl');
137
+ ];
138
+ $controls = $package->getClasses($package->dir,
139
+ 'Drupal\qa\Plugin\Qa\Control\BaseControl');
127
140
128
141
foreach ($controls as $control_name => $control) {
129
142
$default_value = isset($_SESSION[$control_name])
@@ -133,37 +146,39 @@ function qa_report_form($form, $form_state) {
133
146
$collapsed = FALSE;
134
147
}
135
148
136
- $deps = array() ;
149
+ $deps = [] ;
137
150
$met = TRUE;
138
151
foreach ($control->getDependencies() as $dep_name) {
139
- if (module_exists($dep_name)) {
140
- $deps[] = t('@module (<span class="admin-enabled">available</span>)', array('@module' => $dep_name));
152
+ if (Drupal::moduleHandler()->moduleExists($dep_name)) {
153
+ $deps[] = t('@module (<span class="admin-enabled">available</span>)',
154
+ ['@module' => $dep_name]);
141
155
}
142
156
else {
143
- $deps[] = t('@module (<span class="admin-disabled">unavailable</span>)', array('@module' => $dep_name));
157
+ $deps[] = t('@module (<span class="admin-disabled">unavailable</span>)',
158
+ ['@module' => $dep_name]);
144
159
$met = FALSE;
145
160
}
146
161
}
147
- $form[$package_name][$control_name] = array(
148
- '#type' => 'checkbox',
162
+ $form[$package_name][$control_name] = [
163
+ '#type' => 'checkbox',
149
164
'#default_value' => $met ? $default_value : 0,
150
- '#title' => filter_xss_admin ($control->title),
151
- '#description' => filter_xss_admin ($control->description),
152
- '#disabled' => !$met,
153
- ) ;
154
- $form[$package_name][$control_name .'-dependencies'] = array(
155
- '#value' => t('Depends on: !dependencies', array(
165
+ '#title' => Xss::filterAdmin ($control->title),
166
+ '#description' => Xss::filterAdmin ($control->description),
167
+ '#disabled' => !$met,
168
+ ] ;
169
+ $form[$package_name][$control_name . '-dependencies'] = [
170
+ '#value' => t('Depends on: !dependencies', [
156
171
'!dependencies' => implode(', ', $deps),
157
- ) ),
172
+ ] ),
158
173
'#prefix' => '<div class="admin-dependencies">',
159
174
'#suffix' => '</div>',
160
- ) ;
175
+ ] ;
161
176
}
162
177
$form[$package_name]['#collapsed'] = $collapsed;
163
178
}
164
179
165
180
$form['submit'] = [
166
- '#type' => 'submit',
181
+ '#type' => 'submit',
167
182
'#value' => t('Run controls'),
168
183
];
169
184
@@ -177,37 +192,40 @@ function qa_report_form($form, $form_state) {
177
192
* @param array $form_state
178
193
*/
179
194
function qa_report_form_submit($form, &$form_state) {
180
- $controls = array() ;
195
+ $controls = [] ;
181
196
foreach ($form_state['values'] as $item => $value) {
182
- if (class_exists($item) && is_subclass_of($item, '\Drupal\qa\Plugin\Qa\Control\BaseControl')) {
197
+ if (class_exists($item) && is_subclass_of($item,
198
+ '\Drupal\qa\Plugin\Qa\Control\BaseControl')) {
183
199
if ($value) {
184
200
$controls[$item] = $value;
185
201
}
186
202
$_SESSION[$item] = $value;
187
203
}
188
204
elseif ($value == 1) {
189
- $args = array(
205
+ $args = [
190
206
'%control' => $item,
191
- );
192
- drupal_set_message(t('Requested invalid control %control', $args), 'error');
193
- watchdog('qa', 'Requested invalid control %control', $args, WATCHDOG_ERROR);
207
+ ];
208
+ drupal_set_message(t('Requested invalid control %control', $args),
209
+ 'error');
210
+ \Drupal::logger('qa')->error('Requested invalid control %control', $args);
194
211
}
195
212
}
196
213
197
- drupal_set_message(t('Prepare to run these controls: @controls', array(
198
- '@controls' => implode(', ', array_keys($controls)))), 'status');
199
- $batch = array(
200
- 'operations' => array(),
201
- 'title' => t('QA Controls running'),
202
- 'init_message' => t('QA Controls initializing'),
214
+ drupal_set_message(t('Prepare to run these controls: @controls', [
215
+ '@controls' => implode(', ', array_keys($controls)),
216
+ ]), 'status');
217
+ $batch = [
218
+ 'operations' => [],
219
+ 'title' => t('QA Controls running'),
220
+ 'init_message' => t('QA Controls initializing'),
203
221
// 'progress_message' => t('current: @current, Remaining: @remaining, Total: @total'),
204
- 'error_message' => t('Error in QA Control'),
205
- 'finished' => 'qa_report_finished',
222
+ 'error_message' => t('Error in QA Control'),
223
+ 'finished' => 'qa_report_finished',
206
224
// 'file' => '', // only if outside module file
207
- ) ;
225
+ ] ;
208
226
209
227
foreach ($controls as $item => $value) {
210
- $batch['operations'][] = array( 'qa_report_run_pass', array( $item)) ;
228
+ $batch['operations'][] = [ 'qa_report_run_pass', [ $item]] ;
211
229
}
212
230
batch_set($batch);
213
231
}
@@ -218,23 +236,29 @@ function qa_report_form_submit($form, &$form_state) {
218
236
* @return void
219
237
*/
220
238
function qa_report_run_pass($class_name, &$context) {
221
- $name_arg = array( '@class' => $class_name) ;
239
+ $name_arg = [ '@class' => $class_name] ;
222
240
223
241
$control = new $class_name();
224
242
if (!is_object($control)) {
225
- drupal_set_message(t('Cannot obtain an instance for @class', $name_arg), 'error');
226
- $context['results']['#message'] = t('Control @class failed to run.', $name_arg);
243
+ drupal_set_message(t('Cannot obtain an instance for @class', $name_arg),
244
+ 'error');
245
+ $context['results']['#message'] = t('Control @class failed to run.',
246
+ $name_arg);
227
247
$context['message'] = t('Control @class failed to run.', $name_arg);
228
248
$context['results'][$class_name] = 'wow';
229
249
}
230
250
else {
231
- drupal_set_message(t('Running a control instance for @class', $name_arg), 'status');
251
+ drupal_set_message(t('Running a control instance for @class', $name_arg),
252
+ 'status');
232
253
$pass = $control->run();
233
254
if (!$pass->status) {
234
255
$context['success'] = FALSE;
235
256
}
236
257
$context['results']['#message'][] = t('Control @class ran', $name_arg);
237
- $context['message'] = theme('item_list', $context['results']['#message']);
258
+ $context['message'] = \Drupal::service('renderer')->render([
259
+ '#theme' => 'item_list',
260
+ '#items' => $context['results']['#message'],
261
+ ]);
238
262
$context['results'][$class_name] = $pass;
239
263
}
240
264
}
0 commit comments