Commit 630daece authored by NickWilde's avatar NickWilde

Issue #2665150 by NickWilde, vbouchet: Different number of rows on first slide [patch attached]

parent eaa764bf
......@@ -61,6 +61,8 @@ class Cycle extends ViewsSlideshowTypeBase {
'nowrap' => ['default' => 0],
'fixed_height' => ['default' => 1],
'items_per_slide' => ['default' => 1],
'items_per_slide_first' => array('default' => FALSE),
'items_per_slide_first_number' => array('default' => 1),
'wait_for_image_load' => ['default' => 1],
'wait_for_image_load_timeout' => ['default' => 3000],
......@@ -361,6 +363,30 @@ class Cycle extends ViewsSlideshowTypeBase {
],
],
];
$form['views_slideshow_cycle']['items_per_slide_first'] = [
'#type' => 'checkbox',
'#title' => t('Different first slide'),
'#default_value' => $this->getConfiguration()['items_per_slide_first'],
'#description' => t('Different number of items for the first slide'),
'#states' => [
'visible' => [
':input[name="style_options[views_slideshow_cycle][action_advanced]"]' => ['checked' => TRUE],
],
],
];
$form['views_slideshow_cycle']['items_per_slide_first_number'] = [
'#type' => 'textfield',
'#title' => t('Items for first slide'),
'#default_value' => $this->getConfiguration()['items_per_slide_first_number'],
'#description' => t('The number of items for the first slide'),
'#size' => 4,
'#states' => [
'visible' => [
':input[name="style_options[views_slideshow_cycle][action_advanced]"]' => ['checked' => TRUE],
':input[name="style_options[views_slideshow_cycle][items_per_slide_first]"]' => ['checked' => TRUE],
],
],
];
$form['views_slideshow_cycle']['wait_for_image_load'] = [
'#type' => 'checkbox',
'#title' => t('Wait for all the slide images to load'),
......
......@@ -39,9 +39,19 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
$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' => count($rows),
'num_divs' => ceil($num_divs),
'id_prefix' => '#views_slideshow_cycle_main_',
'div_prefix' => '#views_slideshow_cycle_div_',
'vss_id' => $vss_id,
......@@ -101,7 +111,21 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
$vars['rendered_rows'] = [];
foreach ($rows as $count => $item) {
$items[] = $item;
if (count($items) == $settings['items_per_slide'] || $count == (count($rows) - 1)) {
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,
......@@ -170,39 +194,43 @@ function template_preprocess_views_slideshow_cycle_main_frame_row_item(&$vars) {
*/
function _views_slideshow_cycle_preprocess_views_slideshow_pager_fields(&$vars) {
$slide_count = count($vars['view']->result);
$items_per_slide = $vars['view']->style_plugin->options['views_slideshow_cycle']['items_per_slide'];
$options = $vars['view']->style_plugin->options['views_slideshow_cycle'];
$items_per_slide = $options['items_per_slide'];
if ($vars['view']->style_plugin->options['slideshow_type'] == 'views_slideshow_cycle') {
$slide_count = $slide_count / $items_per_slide;
$slide_count = ceil($slide_count);
if ($vars['settings']['hide_on_single_slide'] && $slide_count == 1) {
return;
}
$vars['rendered_field_items'] = [];
if (empty($vars['settings']['hide_on_single_slide']) || $slide_count > 1) {
foreach ($vars['view']->result as $count => $node) {
if ($count < $slide_count) {
$rendered_fields = [];
foreach ($vars['settings']['views_slideshow_pager_fields']['views_slideshow_pager_fields_fields'] as $field => $use) {
if ($use !== 0 && is_object($vars['view']->field[$field])) {
$rendered_fields[] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_field'),
'#view' => $vars['view'],
'#label' => $vars['view']->field[$field]->options['label'],
'#output' => $vars['view']->style_plugin->getField($count, $field),
'#css_identifier' => Html::cleanCssIdentifier($vars['view']->field[$field]->field),
];
}
}
$vars['rendered_field_items'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_item'),
'#vss_id' => $vars['vss_id'],
'#item' => $rendered_fields,
'#count' => $count,
'#location' => $vars['location'],
for ($slide = 0, $count=0; $slide < $slide_count; $count++) {
$rendered_fields = [];
foreach ($vars['settings']['views_slideshow_pager_fields']['views_slideshow_pager_fields_fields'] as $field => $use) {
if ($use !== 0 && is_object($vars['view']->field[$field])) {
$rendered_fields[] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_field'),
'#view' => $vars['view'],
'#label' => $vars['view']->field[$field]->options['label'],
'#output' => $vars['view']->style_plugin->getField($slide, $field),
'#css_identifier' => Html::cleanCssIdentifier($vars['view']->field[$field]->field),
];
}
}
if (empty($vars['rendered_field_items']) && $options['items_per_slide_first']) {
$slide += $options['items_per_slide_first_number'];
}
elseif ($options['items_per_slide']) {
$slide += $options['items_per_slide'];
}
else {
$slide += 1;
}
$vars['rendered_field_items'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_item'),
'#vss_id' => $vars['vss_id'],
'#item' => $rendered_fields,
'#count' => $count,
'#location' => $vars['location'],
];
}
}
......@@ -210,8 +238,14 @@ function _views_slideshow_cycle_preprocess_views_slideshow_pager_fields(&$vars)
* Implements hook_preprocess_views_slideshow_slide_counter().
*/
function _views_slideshow_cycle_preprocess_views_slideshow_slide_counter(&$vars) {
if ($vars['view']->style_plugin->options['slideshow_type'] == 'views_slideshow_cycle') {
$vars['slide_count'] = $vars['slide_count'] / $vars['view']->style_plugin->options['views_slideshow_cycle']['items_per_slide'];
$vars['slide_count'] = ceil($vars['slide_count']);
$options = $vars['view']->style_plugin->options['views_slideshow_cycle'];
if ($options['items_per_slide_first']) {
$slide_count = $vars['slide_count'] - $options['items_per_slide_first_number'];
$slide_count = $slide_count / $options['items_per_slide'];
$slide_count += 1;
}
else {
$slide_count = $vars['slide_count'] / $options['items_per_slide'];
}
$vars['slide_count'] = ceil($slide_count);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment