function template_preprocess_quail_api_results in Quail API 8
Same name and namespace in other branches
- 7 quail_api.module \template_preprocess_quail_api_results()
Template preprocess function for quail_api_results.tpl.php.
File
- ./
quail_api.module, line 54 - Module file for the quail api.
Code
function template_preprocess_quail_api_results(&$variables) {
$root_class_name = 'quail_api-results';
if (!isset($variables['quail_severity_id'])) {
$variables['quail_severity_id'] = NULL;
}
if (!isset($variables['quail_severity_machine_name'])) {
$variables['quail_severity_machine_name'] = '';
}
if (!isset($variables['quail_severity_human_name'])) {
$variables['quail_severity_human_name'] = '';
}
if (!isset($variables['quail_severity_description'])) {
$variables['quail_severity_description'] = '';
}
if (!isset($variables['quail_base_class'])) {
$variables['quail_base_class'] = $root_class_name;
}
if (!isset($variables['quail_specific_class'])) {
$variables['quail_specific_class'] = 'unknown';
}
if (!isset($variables['quail_renderred_tests'])) {
$variables['quail_renderred_tests'] = '';
}
if (empty($variables['quail_severity_results']) || !isset($variables['quail_severity_results']['total'])) {
$quail_severity_results = array(
'total' => 0,
);
}
if (is_numeric($variables['quail_severity_id'])) {
if (empty($variables['quail_severity_array'])) {
$severity = \Drupal\quail_api\QuailApiSettings::get_severity($variables['quail_severity_id']);
}
else {
$severity = $variables['quail_severity_array'];
}
$variables['quail_severity_id'] = $severity['id'];
$variables['quail_severity_machine_name'] = $severity['machine_name'];
$variables['quail_severity_human_name'] = $severity['human_name'];
$variables['quail_severity_description'] = $severity['description'];
$variables['quail_specific_class'] = $root_class_name . '-' . $severity['machine_name'];
}
unset($variables['quail_severity_array']);
// limit quail_title_block to a specific list of html tags
if (!in_array($variables['quail_title_block'], array(
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'div',
'span',
'p',
))) {
$variables['quail_title_block'] = 'h3';
}
$fallback_filter_format = \Drupal::config('quail_api.settings')
->get('filter_format');
if (empty($fallback_filter_format)) {
$fallback_filter_format = filter_fallback_format();
}
$quail_renderred_tests = [];
foreach ($variables['quail_severity_results'] as $test_name => $test_results) {
if ($test_name === 'total') {
continue;
}
$quail_renderred_tests[] = [
'#theme' => 'quail_api_test',
'#quail_test_name' => $test_name,
'#quail_test_results' => $test_results,
'#quail_markup_format' => is_null($variables['quail_markup_format']) ? $fallback_filter_format : $variables['quail_markup_format'],
];
}
if (!empty($quail_renderred_tests)) {
$variables['quail_renderred_tests'] = \Drupal::service('renderer')
->render($quail_renderred_tests, FALSE);
}
}