You are here

function template_preprocess_views_bootstrap_carousel in Views Bootstrap 8.4

Same name and namespace in other branches
  1. 8.3 views_bootstrap.theme.inc \template_preprocess_views_bootstrap_carousel()

Prepares variables for views carousel template.

Default template: views-bootstrap-carousel.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_carousel'
ViewsBootstrap::getThemeHooks in src/ViewsBootstrap.php
Returns the theme hook definition information.

File

./views_bootstrap.theme.inc, line 85
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_bootstrap_carousel(array &$vars) {
  $view = $vars['view'];
  $vars['id'] = ViewsBootstrap::getUniqueId($view);
  $vars['attributes']['class'][] = 'views-bootstrap-media-object';
  $vars['attributes']['class'][] = 'media-list';

  // Carousel options.
  $vars['interval'] = $view->style_plugin->options['interval'];
  $vars['navigation'] = $view->style_plugin->options['navigation'];
  $vars['indicators'] = $view->style_plugin->options['indicators'];
  $vars['pause'] = $view->style_plugin->options['pause'] ? 'hover' : FALSE;
  $vars['wrap'] = $view->style_plugin->options['wrap'];
  $vars['effect'] = $view->style_plugin->options['effect'];
  $vars['use_caption'] = $view->style_plugin->options['use_caption'];
  $vars['ride'] = $view->style_plugin->options['ride'];

  // Carousel rows.
  $image = $view->style_plugin->options['image'];
  $title = $view->style_plugin->options['title'];
  $description = $view->style_plugin->options['description'];
  $fieldLabels = $view->display_handler
    ->getFieldLabels(TRUE);
  foreach ($vars['rows'] as $id => $row) {
    $vars['rows'][$id] = [];
    $vars['rows'][$id]['image'] = $view->style_plugin
      ->getField($id, $image);
    $vars['rows'][$id]['title'] = $view->style_plugin
      ->getField($id, $title);
    $vars['rows'][$id]['description'] = $view->style_plugin
      ->getField($id, $description);

    // Add any additional fields to result.
    foreach (array_keys($fieldLabels) as $label) {
      if (!in_array($label, [
        $image,
        $title,
        $description,
      ])) {
        $vars['rows'][$id][$label] = $view->style_plugin
          ->getField($id, $label);
      }
    }
  }
}