function template_preprocess_quail_api_test in Quail API 8
Same name and namespace in other branches
- 7 quail_api.module \template_preprocess_quail_api_test()
Template preprocess function for quail_api_test.tpl.php.
File
- ./
quail_api.module, line 135 - Module file for the quail api.
Code
function template_preprocess_quail_api_test(&$variables) {
$root_class_name = 'quail_api-test';
if (!isset($variables['quail_base_class'])) {
$variables['quail_base_class'] = $root_class_name;
}
if (!isset($variables['quail_specific_class'])) {
$variables['quail_specific_class'] = '';
}
if (!isset($variables['quail_test_title'])) {
$variables['quail_test_title'] = '';
}
if (!isset($variables['quail_test_description'])) {
$variables['quail_test_description'] = '';
}
if (!isset($variables['quail_test_problems'])) {
$variables['quail_test_problems'] = array();
}
if (!empty($variables['quail_test_name'])) {
$variables['quail_specific_class'] = $root_class_name . '-' . Drupal\Component\Utility\Unicode::strtolower(\Drupal\Component\Utility\Html::escape($variables['quail_test_name']));
}
$fallback_filter_format = filter_fallback_format();
if (!empty($variables['quail_test_results']['body']['title'])) {
$variables['quail_test_title'] = $variables['quail_test_results']['body']['title'];
if (isset($variables['quail_test_results']['body']['description'])) {
// drupal 8.4 and earlier seem to have issues with NULL being passed as the markup format.
if (is_null($variables['quail_markup_format'])) {
$variables['quail_test_description'] = check_markup($variables['quail_test_results']['body']['description'], $fallback_filter_format);
}
else {
$variables['quail_test_description'] = check_markup($variables['quail_test_results']['body']['description'], $variables['quail_markup_format']);
}
}
if (!empty($variables['quail_test_results']['problems'])) {
$variables['quail_test_problems'] = $variables['quail_test_results']['problems'];
}
}
$variables['quail_test_note'] = '';
if (isset($variables['quail_test_problems']['message'])) {
$variables['quail_test_note'] = $variables['quail_test_problems']['message'];
unset($variables['quail_test_problems']['message']);
}
unset($variables['quail_test_name']);
unset($variables['quail_test_results']);
$renderred_problems = array();
foreach ($variables['quail_test_problems'] as $problem_id => $problem_data) {
if (!is_numeric($problem_id)) {
continue;
}
$renderred_problems[] = array(
'#theme' => 'quail_api_problem',
'#quail_problem_id' => $problem_id,
'#quail_problem_data' => $problem_data,
'#quail_markup_format' => is_null($variables['quail_markup_format']) ? $fallback_filter_format : $variables['quail_markup_format'],
);
}
$variables['quail_renderred_problems'] = '';
if (!empty($renderred_problems)) {
// this is the expanded version of the deprecated drupal_render() function
// (consider RendererInterface::render()).
$variables['quail_renderred_problems'] = \Drupal::service('renderer')
->render($renderred_problems, FALSE);
}
}