function template_preprocess_views_bootstrap_tab in Views Bootstrap 8.3
Same name and namespace in other branches
- 8.4 views_bootstrap.theme.inc \template_preprocess_views_bootstrap_tab()
Prepares variables for views tab templates.
Default template: views-bootstrap-tab.html.twig.
Parameters
array $vars: An associative array containing:
- view: A ViewExecutable object.
- rows: The raw row data.
1 string reference to 'template_preprocess_views_bootstrap_tab'
- ViewsBootstrap::getThemeHooks in src/
ViewsBootstrap.php - Returns the theme hook definition information.
File
- ./
views_bootstrap.theme.inc, line 301 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_views_bootstrap_tab(array &$vars) {
$vars['id'] = ViewsBootstrap::getUniqueId($vars['view']);
$view = $vars['view'];
$group_title_field = isset($view->style_plugin->options['grouping'][0]) ? $view->style_plugin->options['grouping'][0]['field'] : "";
$tab_field = $view->style_plugin->options['tab_field'];
$vars['tab_type'] = $view->style_plugin->options['tab_type'];
$vars['tab_position'] = $view->style_plugin->options['tab_position'];
$vars['tab_fade'] = $view->style_plugin->options['tab_fade'] ? 'fade' : '';
// Get tabs.
if ($tab_field) {
if (isset($view->field[$tab_field])) {
foreach (array_keys($vars['rows']) as $key) {
$vars['tabs'][$key] = [
'#markup' => Xss::filter($view->style_plugin
->getField($key, $tab_field), [
'img',
'br',
'h2',
'h3',
'h4',
'h5',
'h6',
'span',
'strong',
'em',
'i',
'small',
]),
];
}
}
foreach ($vars['rows'] as $id => $row) {
$vars['group_title'] = $group_title_field ? $view->style_plugin
->getField($id, $group_title_field) : "";
$vars['rows'][$id] = [];
$vars['rows'][$id]['content'] = $row;
$vars['rows'][$id]['attributes'] = new Attribute();
if ($row_class = $view->style_plugin
->getRowClass($id)) {
$vars['rows'][$id]['attributes']
->addClass($row_class);
}
}
}
else {
// @TODO: This would be better as validation errors on the style plugin options form.
Drupal::messenger()
->addWarning(t('@style style will not display without the "@field" setting.', [
'@style' => $view->style_plugin->definition['title'],
'@field' => 'Tab title',
]));
}
}