function template_preprocess_search_api_admin_data_type_table in Search API 8
Prepares variables for search_api_admin_data_type_table form templates.
Default template: search-api-admin-data-type-table.html.twig.
Parameters
array &$variables: An associative array containing:
- data_types: An associative array of data types, keyed by data type ID and
containing associative arrays with information about the data type:
- label: The (translated) human-readable label for the data type.
- description: The (translated) description of the data type.
- fallback: The type ID of the fallback type.
- fallback_mapping: array of fallback data types for unsupported data types.
- table: The data types table.
File
- ./
search_api.theme.inc, line 76 - Defines theme functions for the Search API module.
Code
function template_preprocess_search_api_admin_data_type_table(array &$variables) {
$data_types = $variables['data_types'];
$fallback_mapping = $variables['fallback_mapping'];
$header = [
t('Data Type'),
t('Description'),
t('Supported'),
];
// Only show the column with fallback types if there is actually an
// unsupported type listed.
if ($fallback_mapping) {
$header[] = t('Fallback data type');
}
$rows = [];
$yes = t('Yes');
$yes_img = 'core/misc/icons/73b355/check.svg';
$no = t('No');
$no_img = 'core/misc/icons/e32700/error.svg';
foreach ($data_types as $data_type_id => $data_type) {
$has_fallback = isset($fallback_mapping[$data_type_id]);
$supported_label = $has_fallback ? $no : $yes;
$supported_icon = [
'#theme' => 'image',
'#uri' => $has_fallback ? $no_img : $yes_img,
'#width' => 18,
'#height' => 18,
'#alt' => $supported_label,
'#title' => $supported_label,
];
$row = [
$data_type['label'],
$data_type['description'],
[
'data' => $supported_icon,
],
];
if ($fallback_mapping) {
$row[] = $has_fallback ? $data_types[$data_type['fallback']]['label'] : '';
}
$rows[] = $row;
}
$variables['table'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
];
}