You are here

function template_preprocess_views_view_jcarousel in jCarousel 8.4

Same name and namespace in other branches
  1. 8.5 jcarousel.module \template_preprocess_views_view_jcarousel()
  2. 7.3 includes/jcarousel.views.inc \template_preprocess_views_view_jcarousel()

File

./jcarousel.module, line 563
Provides integration with 3rd party modules and the jCarousel library.

Code

function template_preprocess_views_view_jcarousel(&$variables) {

  /** @var \Drupal\views\ViewExecutable $view */
  $view =& $variables['view'];
  $variables['options'] = $view->style_plugin->options;
  $position = array_search('jcarousel/jcarousel', $view->element['#attached']['library']);
  $library = array_splice($view->element['#attached']['library'], $position, 1);
  $view->element['#attached']['library'] = array_merge($view->element['#attached']['library'], $library);
  $variables['options']['preload_page'] = 0;

  // Build the list of classes for the carousel.
  // $variables['options'] = $view->getStyle()->options;
  // If using AJAX, adjust the view's positioning based on the current page.
  if ($view
    ->ajaxEnabled() && $view
    ->usePager()) {
    if ($view->pager
      ->getPluginId() == 'jcarousel_pager') {
      if ($view->pager->total_items == PHP_INT_MAX / 2) {

        // Attach preload.
        $variables['options']['preload_page'] = $view
          ->getCurrentPage() + 1;
      }
      $variables['options']['ajax'] = TRUE;
      if (empty($variables['options']['ajax_path'])) {
        $variables['options']['ajax_path'] = 'jcarousel/views/ajax';
      }
    }
  }
  unset($variables['attributes']);
  $variables += _jcarousel_generate_attributes($variables['rows'], $variables['options']);
  $variables['items'] = $variables['rows'];
}