You are here

function template_preprocess_views_bootstrap_tab in Views Bootstrap 8.4

Same name and namespace in other branches
  1. 8.3 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 209
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'];
  $tab_field = $view->style_plugin->options['tab_field'];
  $vars['tab_type'] = $view->style_plugin->options['tab_type'];
  $vars['justified'] = $view->style_plugin->options['justified'];

  // Get tabs.
  if ($tab_field) {
    if (isset($view->field[$tab_field])) {
      foreach (array_keys($vars['rows']) as $key) {
        $vars['tabs'][$key] = $view->style_plugin
          ->getFieldValue($key, $tab_field);
      }
    }
    foreach ($vars['rows'] as $id => $row) {
      $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 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' => 'Tab title',
    ]));
  }
}