function template_preprocess_uikit_view_slideshow in UIkit Components 8.3
Prepares variables for UIkit Slideshow templates.
Default template: uikit-view-slideshow.html.twig.
Parameters
array $variables: An associative array containing:
- view: A ViewExecutable object.
- rows: The raw row data.
1 string reference to 'template_preprocess_uikit_view_slideshow'
- UIkitViews::getThemeHooks in uikit_views/
src/ UIkitViews.php - Returns the theme hook definition information for UIkit Views.
File
- uikit_views/
includes/ uikit_views.theme.inc, line 270 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_uikit_view_slideshow(array &$variables) {
$view = $variables['view'];
$options = $view->style_plugin->options;
// Add option to the variables array.
foreach ($options as $option => $value) {
$variables[$option] = $value;
}
$items = [];
// Iterate over each rendered views result row.
foreach ($variables['rows'] as $result_index => $item) {
if ($options['image_field']) {
$image = $view->style_plugin
->getField($result_index, $options['image_field']);
$items[$result_index]['image'] = $image;
}
if ($options['title_field']) {
$title = $view->style_plugin
->getField($result_index, $options['title_field']);
$items[$result_index]['title'] = $title;
}
if ($options['caption_field']) {
$caption = $view->style_plugin
->getField($result_index, $options['caption_field']);
$items[$result_index]['caption'] = $caption;
}
if ($options['thumbnav'] && $options['thumbnav_field']) {
$thumbnail = $view->style_plugin
->getField($result_index, $options['thumbnav_field']);
$items[$result_index]['thumbnail'] = $thumbnail;
}
}
// Add items to the variables array.
$variables['items'] = $items;
// Create attributes for slideshow.
$slideshow_data = [];
$slideshow_data[] = 'animation: ' . $options['animation'];
$slideshow_data[] = 'autoplay: ' . $options['autoplay'];
$slideshow_data[] = 'autoplay-interval: ' . $options['autoplay_interval'];
$slideshow_data[] = 'finite: ' . $options['finite'];
$slideshow_data[] = 'pause-on-hover: ' . $options['pause_on_hover'];
$slideshow_data[] = 'index: ' . $options['index'];
$slideshow_data[] = 'velocity: ' . $options['velocity'];
$slideshow_data[] = 'ratio: ' . ($options['ratio'] ? $options['ratio'] : 'false');
$slideshow_data[] = 'min-height: ' . (!empty($options['min_height']) ? $options['min_height'] : 'false');
$slideshow_data[] = 'max-height: ' . (!empty($options['max_height']) ? $options['max_height'] : 'false');
if ($options['caption_transition'] != NULL) {
$transition = $options['caption_toggle'] ? '' : 'uk-transition-active';
$slideshow_data[] = "clsActivated: {$transition}";
}
$data_slideshow = implode('; ', $slideshow_data);
$variables['slideshow_attributes'] = new Attribute([
'data-uk-slideshow' => $data_slideshow,
]);
// Create attributes for slidenav.
$variables['slidenav_left_attributes'] = new Attribute([
'data-uk-slidenav-previous' => "",
'data-uk-slideshow-item' => 'previous',
]);
$variables['slidenav_right_attributes'] = new Attribute([
'data-uk-slidenav-next' => "",
'data-uk-slideshow-item' => 'next',
]);
// Set other necessary attributes variables for twig template.
$variables['caption_attributes'] = new Attribute();
$variables['panel_attributes'] = new Attribute();
}