function template_preprocess_search_api_admin_fields_table in Search API 8
Prepares variables for search_api_admin_fields_table form templates.
Default template: search-api-admin-fields-table.html.twig.
Parameters
array &$variables: Associative array of template variables, with the following structure:
- element: Associative array with the following keys:
- form: A render element representing the form.
- note: The table note.
File
- ./
search_api.theme.inc, line 27 - Defines theme functions for the Search API module.
Code
function template_preprocess_search_api_admin_fields_table(array &$variables) {
$form = $variables['element'];
$rows = [];
if (!empty($form['fields'])) {
foreach (Element::children($form['fields']) as $name) {
$row = [];
foreach (Element::children($form['fields'][$name]) as $field) {
if ($cell = render($form['fields'][$name][$field])) {
$row[] = $cell;
}
}
$row = [
'data' => $row,
'data-field-row-id' => $name,
];
if (!empty($form['fields'][$name]['description']['#value'])) {
$row['title'] = strip_tags($form['fields'][$name]['description']['#value']);
}
$rows[] = $row;
}
}
$variables['note'] = $form['note'] ?? '';
unset($form['note'], $form['submit']);
$variables['table'] = [
'#theme' => 'table',
'#header' => $form['#header'],
'#rows' => $rows,
'#empty' => t('No fields have been added for this datasource.'),
];
}