You are here

function template_preprocess_jcarousel in jCarousel 8.4

Same name and namespace in other branches
  1. 8.5 jcarousel.module \template_preprocess_jcarousel()

Preprocess function for jcarousel.html.twig.

File

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

Code

function template_preprocess_jcarousel(&$variables) {

  // Set default options.
  $variables['options'] += [
    'skin' => 'default',
    'scroll' => 1,
    'vertical' => 0,
    'navigation' => 'after',
    'visible' => 4,
  ];
  $options = $variables['options'];

  // Add the jCarousel library and any global settings.
  $variables['#attached']['library'][] = 'jcarousel/jcarousel';

  // Allow other modules to modify these settings.
  \Drupal::moduleHandler()
    ->alter('jcarousel_options', $options, $class_name);
  if (!empty($options['skin'])) {
    $variables['#attached']['library'][] = 'jcarousel/skin.' . $options['skin'];
  }
  $variables['options'] = $options;
  unset($variables['attributes']);
  $variables += _jcarousel_generate_attributes($variables['items'], $variables['options']);
}