You are here

function template_preprocess_slick_slide in Slick Carousel 7.3

Same name and namespace in other branches
  1. 8.2 templates/slick.theme.inc \template_preprocess_slick_slide()
  2. 8 templates/slick.theme.inc \template_preprocess_slick_slide()

Preprocess variables for theme_slick_slide() and slick-slide.tpl.php.

File

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

Code

function template_preprocess_slick_slide(&$variables) {
  _slick_preprocess_item($variables);

  // All slide types: main, thumbnail, grid, overlay -- may have captions.
  // Anything but the main slide is treated as captions for clarity.
  // Variables item may contain `slide` and `caption`.
  foreach ([
    'alt',
    'data',
    'link',
    'overlay',
    'title',
  ] as $key) {

    // Chances are entity_view, or Views flattens out the expected render array.
    // Or a drupal_render() is called too early, or just string passed.
    $caption = isset($variables['item']['caption'][$key]) ? $variables['item']['caption'][$key] : [];
    if ($caption) {
      $caption = is_string($caption) ? [
        '#markup' => $caption,
      ] : $caption;
    }
    $variables['item']['caption'][$key] = $caption;
  }
  $item =& $variables['item'];
  $settings =& $variables['settings'];
  $attributes =& $variables['attributes_array'];
  $content_attributes =& $variables['content_attributes_array'];

  // detroy: Remove .slide__content if it is an enforced unslick grid.
  // fullwidth: If full skins, add wrappers to hold caption and overlay.
  // split: Split image from captions if we do have captions, and main image.
  // use_wrapper: Don't add divities for a single item to have clean markups.
  $item['slide'] = isset($item['slide']) ? $item['slide'] : [];
  $settings['detroy'] = $settings['current_item'] == 'main' && $settings['grid'] && !empty($settings['unslick']);
  $settings['fullwidth'] = !empty($settings['skin']) && strpos($settings['skin'], 'full') !== FALSE;
  $settings['has_data'] = !empty($item['caption']['alt']) || !empty($item['caption']['title']) || !empty($item['caption']['data']);
  $settings['split'] = !empty($item) && (!empty($settings['caption']) || !empty($settings['title']));
  $settings['use_caption'] = !empty(array_filter($item['caption']));
  $settings['use_wrapper'] = $settings['count'] > 1 && $settings['current_item'] != 'grid';
  if (!empty($settings['layout'])) {
    $attributes['class'][] = 'slide--caption--' . str_replace('_', '-', $settings['layout']);
  }
  if (!empty($settings['class'])) {

    // Respects string with spaces such as CSV tags to space delimiter.
    $attributes['class'][] = drupal_strtolower(str_replace('_', '-', $settings['class']));
  }
  $content_attributes['class'][] = $settings['detroy'] ? 'slide' : 'slide__content';
  $variables['caption_attributes_array']['class'][] = 'slide__caption';
  $variables['classes_array'] = $attributes['class'];
}