function template_preprocess_views_bootstrap_accordion in Views Bootstrap 8.3
Same name and namespace in other branches
- 8.4 views_bootstrap.theme.inc \template_preprocess_views_bootstrap_accordion()
Prepares variables for views accordion templates.
Default template: views-bootstrap-accordion.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_accordion'
- ViewsBootstrap::getThemeHooks in src/
ViewsBootstrap.php - Returns the theme hook definition information.
File
- ./
views_bootstrap.theme.inc, line 23 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_views_bootstrap_accordion(array &$vars) {
$view = $vars['view'];
$vars['id'] = ViewsBootstrap::getUniqueId($view);
$group_title_field = isset($view->style_plugin->options['grouping'][0]) ? $view->style_plugin->options['grouping'][0]['field'] : "";
$panel_title_field = $view->style_plugin->options['panel_title_field'];
$vars['behavior'] = $view->style_plugin->options['behavior'];
$label_field = $view->style_plugin->options['label_field'] ?? '';
$vars['attributes']['class'][] = 'panel-group';
if ($panel_title_field) {
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]['label'] = $label_field ? $view->style_plugin
->getField($id, $label_field) : '';
$vars['rows'][$id]['title'] = [
'#markup' => Xss::filter($view->style_plugin
->getField($id, $panel_title_field), [
'img',
'br',
'h2',
'h3',
'h4',
'h5',
'h6',
'span',
'strong',
'em',
'i',
'small',
]),
];
}
}
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' => 'Panel title',
]));
}
// @TODO: Make sure that $vars['rows'] is a rendered array.
// @SEE: Have a look at template_preprocess_views_view_unformatted()
// and views-view-unformatted.html.twig
}