You are here

function template_preprocess_slick_item in Slick Carousel 7.2

Implements hook_preprocess_slick_item().

File

templates/slick.theme.inc, line 218
Hooks and preprocess functions for the Slick module.

Code

function template_preprocess_slick_item(&$variables) {
  $element = $variables['element'];
  $delta = $element['#delta'];
  $item = $variables['item'] = $element['#item'];
  $settings = $element['#settings'];
  $type = isset($item['#item']['type']) ? $item['#item']['type'] : '';

  // Prepare variables, and remove non-BEM default class.
  foreach (array(
    'content',
    'item',
    'title',
    'wrapper',
  ) as $key) {
    $variables[$key . '_prefix'] = $variables[$key . '_suffix'] = '';
  }

  // Configure attributes for containing elements.
  $attributes['class'] = array(
    'slick__slide',
    'slide',
    'slide--' . $delta,
  );

  // Media module has type: image, audio, video, as opposed to field_type.
  if ($type && $type != 'image') {
    $attributes['class'][] = 'slide--' . $type;
  }

  // All slide types -- main, thumbnail, grid, overlay -- may have captions.
  $variables['caption'] = $element['#caption'];
  $variables['slide_pattern'] = '';

  // Title, caption and overlay, or nested media.
  if ($settings['current_item'] != 'thumbnail') {

    // Each slide can have unique, or uniform layout.
    if (!empty($settings['layout'])) {
      $attributes['class'][] = str_replace('_', '-', 'slide--caption--' . $settings['layout']);
    }

    // Split image from captions if we do have captions, and main image.
    if ($variables['caption'] && $item || !empty($settings['skin']) && strpos($settings['skin'], '3d') !== FALSE) {
      $variables['item_prefix'] = '<div class="slide__media">';
      $variables['item_suffix'] = '</div>';
    }

    // If fullwidth or fullscreen, add wrappers to hold caption and overlay.
    if (!empty($settings['skin']) && strpos($settings['skin'], 'full') !== FALSE) {
      $variables['title_prefix'] = '<div class="slide__constrained">';
      $variables['title_suffix'] = '</div>';
    }

    // Exclude lightbox switcher as it has its own pattern DIV within A tag.
    if (!empty($settings['has_pattern']) && empty($settings['lightbox'])) {
      $variables['slide_pattern'] = '<div class="slide__pattern"></div>';
    }

    // Add helper classes for nested sliders.
    if (!empty($settings['nested_slick'])) {
      $attributes['class'][] = $settings['current_item'] == 'overlay' ? 'slide--nested' : 'slide--nester';
    }

    // Custom individual slide classes.
    if (!empty($settings['slide_classes'])) {
      $attributes['class'][] = trim($settings['slide_classes']);
    }
  }

  // Do not add divities for a single slick (unslick) to have clean markups.
  // Or when it is a grid item.
  if ($settings['current_item'] != 'grid') {
    $variables['wrapper_prefix'] = '<div' . drupal_attributes($attributes) . '>';
    $variables['wrapper_suffix'] = '</div>';
  }
  $settings['wrapper'] = $settings['count'] > 1 && $settings['current_item'] != 'grid';
  if ($settings['wrapper'] && empty($settings['grid'])) {
    $variables['content_prefix'] = '<div class="slide__content">';
    $variables['content_suffix'] = '</div>';
  }
  $variables['settings'] = $settings;
}