You are here

function template_preprocess_views_bootstrap_accordion in Views Bootstrap 8.4

Same name and namespace in other branches
  1. 8.3 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 21
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);
  $panel_title_field = $view->style_plugin->options['panel_title_field'];
  $vars['attributes']['class'][] = 'panel-group';
  $vars['options'] = $view->style_plugin->options;
  if ($panel_title_field) {
    foreach ($vars['rows'] as $id => $row) {
      $vars['rows'][$id] = [];
      $vars['rows'][$id]['content'] = $row;
      $vars['rows'][$id]['title'] = $view->style_plugin
        ->getField($id, $panel_title_field);
    }
  }
  else {

    // @TODO: This would be better as valdiation 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 rendered array.
  // @SEE: Have a look template_preprocess_views_view_unformatted()
  // and views-view-unformatted.html.twig
}