You are here

function _slick_preprocess_item in Slick Carousel 7.3

Prepares common variables for slick item.

3 calls to _slick_preprocess_item()
template_preprocess_slick_slide in templates/slick.theme.inc
Preprocess variables for theme_slick_slide() and slick-slide.tpl.php.
theme_slick_thumbnail in templates/slick.theme.inc
Returns HTML for a thumbnail navigation.
theme_slick_vanilla in templates/slick.theme.inc
Returns HTML for a slick_vanilla to render individual slide as is.

File

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

Code

function _slick_preprocess_item(&$variables) {
  _slick_preprocess_attributes($variables);
  foreach ([
    'delta',
    'item',
    'settings',
  ] as $key) {
    $default = $key == 'delta' ? 0 : [];
    $variables[$key] = isset($variables['element']["#{$key}"]) ? $variables['element']["#{$key}"] : $default;
  }

  // Chances are entity_view, or Views flattens out the expected render array.
  // Or a drupal_render() is called too early, or just string passed.
  // Applies to thumbnail caption as well in case bypassing the API.
  foreach ([
    'slide',
    'caption',
  ] as $key) {
    if (!empty($variables['item'][$key]) && is_string($variables['item'][$key])) {
      $variables['item'][$key] = [
        '#markup' => $variables['item'][$key],
      ];
    }
  }

  // With clones, regular CSS :nth-child will fail to style uniquely, add delta.
  $variables['attributes_array']['class'][] = 'slick__slide slide slide--' . $variables['delta'];
}