Same name in other branches
- 7.x-3.x contrib/views_slideshow_cycle/theme/views_slideshow_cycle.theme.inc \template_preprocess_views_slideshow_cycle_main_frame()
- 8.x-3.x modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc \template_preprocess_views_slideshow_cycle_main_frame()
- 8.x-4.x modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc \template_preprocess_views_slideshow_cycle_main_frame()
Views Slideshow: Theme the main frame wrapper.
Sujets associés
Fichier
-
modules/
views_slideshow_cycle/ views_slideshow_cycle.theme.inc, line 15
Code
function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
$settings = $vars['settings'];
$rows = $vars['rows'];
$vss_id = $vars['vss_id'];
// Cast the strings into int or bool as necessary.
$new_settings = [];
foreach ($settings as $key => $value) {
if (is_string($value)) {
$value = str_replace("\n", ' ', $value);
$value = trim($value);
if (is_numeric($value)) {
$value = (int) $value;
}
elseif (strtolower($value) == 'true') {
$value = TRUE;
}
elseif (strtolower($value) == 'false') {
$value = FALSE;
}
}
$new_settings[$key] = $value;
}
$num_divs = count($rows);
if ($settings['items_per_slide_first']) {
$num_divs -= $settings['items_per_slide_first_number'];
$num_divs = $num_divs / $settings['items_per_slide'];
$num_divs += 1;
}
else {
$num_divs = $num_divs / $settings['items_per_slide'];
}
$settings = array_merge([
'num_divs' => ceil($num_divs),
'id_prefix' => '#views_slideshow_cycle_main_',
'div_prefix' => '#views_slideshow_cycle_div_',
'vss_id' => $vss_id,
], $new_settings);
// We need to go through the current js setting values to make sure the one we
// want to add is not already there. If it is already there then append -[num]
// to the id to make it unique.
$slideshow_count = 1;
global $_views_slideshow_processedCycles;
if (is_array($_views_slideshow_processedCycles)) {
foreach ($_views_slideshow_processedCycles as $processedCycle) {
if (stristr($processedCycle, '#views_slideshow_cycle_main_' . $vss_id)) {
$slideshow_count++;
}
}
}
if ($slideshow_count > 1) {
$vss_id .= '-' . $slideshow_count;
$settings['vss_id'] = $vss_id;
}
// Load the json2 library.
if (!empty($settings['advanced_options'])) {
$vars['#attached']['library'][] = 'views_slideshow_cycle/json2';
}
// Load the pause library.
if (!empty($settings['pause_in_middle'])) {
$vars['#attached']['library'][] = 'views_slideshow_cycle/jquery_pause';
}
// Load jQuery Cycle library.
$vars['#attached']['library'][] = 'views_slideshow_cycle/jquery_cycle';
// Load our custom cycle library.
$vars['#attached']['library'][] = 'views_slideshow_cycle/views_slideshow_cycle';
$vars['#attached']['drupalSettings']['viewsSlideshowCycle']['#views_slideshow_cycle_main_' . $vss_id] = $settings;
$_views_slideshow_processedCycles['#views_slideshow_cycle_main_' . $vss_id] = '#views_slideshow_cycle_main_' . $vss_id;
// Add hover intent library.
if ($settings['pause']) {
$vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent';
}
// Add the slideshow elements.
$vars['attributes']['class'][] = 'views_slideshow_cycle_teaser_section';
$vars['items_per_slide'] = $settings['items_per_slide'];
$items = [];
$index = 0;
$vars['rendered_rows'] = [];
foreach ($rows as $count => $item) {
$items[] = $item;
if ($settings['items_per_slide_first'] && empty($vars['rendered_rows'])) {
if (count($items) == $settings['items_per_slide_first_number'] || $count == count($rows) - 1) {
$vars['rendered_rows'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row'),
'#vss_id' => $vss_id,
'#items' => $items,
'#count' => $index,
'#view' => $vars['view'],
];
$items = [];
$index++;
}
}
elseif (count($items) == $settings['items_per_slide'] || $count == count($rows) - 1) {
$vars['rendered_rows'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row'),
'#vss_id' => $vss_id,
'#items' => $items,
'#count' => $index,
'#view' => $vars['view'],
];
$items = [];
$index++;
}
}
}