You are here

function template_preprocess_views_slideshow in Views Slideshow 7.3

Same name and namespace in other branches
  1. 6.3 views_slideshow.module \template_preprocess_views_slideshow()
  2. 6.2 views_slideshow.module \template_preprocess_views_slideshow()

Implements hook_preprocess_views_slideshow().

Related topics

1 call to template_preprocess_views_slideshow()
_views_slideshow_preprocess_views_slideshow in theme/views_slideshow.theme.inc
Backwards compatibility wrapper.

File

theme/views_slideshow.theme.inc, line 30
The theme system, which controls the output of views slideshow.

Code

function template_preprocess_views_slideshow(&$vars) {
  $options = $vars['options'];
  $vars['skin'] = 'default';
  $vars['slideshow'] = '';
  $main_frame_module = $options['slideshow_type'];
  if (empty($main_frame_module)) {

    // Get all slideshow types.
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
    if ($slideshows) {
      foreach ($slideshows as $slideshow_id => $slideshow_info) {
        $main_frame_module = $slideshow_id;
        break;
      }
    }
  }

  // Make sure the main slideshow settings are defined before building the
  // slideshow.
  if (empty($main_frame_module)) {
    drupal_set_message(t('No main frame module is enabled for views slideshow. This is often because another module which Views Slideshow needs is not enabled. For example, 3.x needs a module like "Views Slideshow: Cycle" enabled.'), 'error');
  }
  elseif (empty($options[$main_frame_module])) {
    drupal_set_message(t('The options for !module does not exists.', array(
      '!module' => $main_frame_module,
    )), 'error');
  }
  elseif (!empty($vars['rows'])) {
    $settings = $options[$main_frame_module];
    $view = $vars['view'];
    $rows = $vars['rows'];
    $vss_id = $view->name . '-' . $view->current_display;

    // Give each slideshow a unique id if there are more than one on the page.
    static $instances = array();
    if (isset($instances[$vss_id])) {
      $instances[$vss_id]++;
      $vss_id .= "_" . $instances[$vss_id];
    }
    else {
      $instances[$vss_id] = 1;
      $vss_id .= '_1';
    }

    // Building our default methods.
    $methods = array(
      'goToSlide' => array(),
      'nextSlide' => array(),
      'pause' => array(),
      'play' => array(),
      'previousSlide' => array(),
      'transitionBegin' => array(),
      'transitionEnd' => array(),
    );

    // Pull all widget info and slideshow info and merge them together.
    $widgets = module_invoke_all('views_slideshow_widget_info');
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
    $addons = array_merge($widgets, $slideshows);

    // Loop through all the addons and call their methods if needed.
    foreach ($addons as $addon_id => $addon_info) {
      foreach ($addon_info['accepts'] as $imp_key => $imp_value) {
        if (is_array($imp_value)) {
          $methods[$imp_key][] = views_slideshow_format_addons_name($addon_id);
        }
        else {
          $methods[$imp_value][] = views_slideshow_format_addons_name($addon_id);
        }
      }
    }
    $js_settings = array(
      'viewsSlideshow' => array(
        $vss_id => array(
          'methods' => $methods,
          'paused' => 0,
        ),
      ),
    );
    drupal_add_library('views_slideshow', 'views_slideshow');
    drupal_add_js($js_settings, 'setting');

    // Process Skins.
    $skin_info = array();
    if (isset($options['skin_info'])) {
      $skin_info = $options['skin_info'];
    }

    // Make sure $skin_info has all the values.
    $skin_info += array(
      'class' => 'default',
      'name' => t('Untitled skin'),
      'module' => 'views_slideshow',
      'path' => '',
      'stylesheets' => array(),
    );
    $vars['skin'] = $skin_info['class'];

    // Enqueue any stylesheets set for the skin on this view are added.
    $skin_path = drupal_get_path('module', $skin_info['module']);
    if ($skin_info['path']) {
      $skin_path .= '/' . $skin_info['path'];
    }

    // Add stylesheet.
    if (!empty($skin_info['stylesheets'])) {
      foreach ($skin_info['stylesheets'] as $stylesheet) {
        drupal_add_css($skin_path . '/' . $stylesheet);
      }
    }

    // Process Widgets.
    // Build weights.
    for ($i = 1; $i <= count($widgets); $i++) {
      $weight['top'][$i] = array();
      $weight['bottom'][$i] = array();
    }
    foreach ($widgets as $widget_id => $widget_name) {

      // Put our widgets in the right location.
      if ($options['widgets']['top'][$widget_id]['enable']) {
        $widget_weight = $options['widgets']['top'][$widget_id]['weight'] > count($widgets) ? count($widgets) : $options['widgets']['top'][$widget_id]['weight'];
        $weight['top'][$widget_weight][] = $widget_id;
      }
      if ($options['widgets']['bottom'][$widget_id]['enable']) {
        $widget_weight = $options['widgets']['bottom'][$widget_id]['weight'] > count($widgets) ? count($widgets) : $options['widgets']['bottom'][$widget_id]['weight'];
        $weight['bottom'][$widget_weight][] = $widget_id;
      }
    }

    // Build our widgets.
    foreach ($weight as $location => $order) {
      $vars[$location . '_widget_rendered'] = '';
      foreach ($order as $order_num => $widgets) {
        if (is_array($widgets)) {
          foreach ($widgets as $widget_id) {
            $vars[$widget_id . '_' . $location] = theme(views_theme_functions($widget_id . '_widget_render', $view, $view->display[$view->current_display]), array(
              'vss_id' => $vss_id,
              'view' => $view,
              'settings' => $options['widgets'][$location][$widget_id],
              'location' => $location,
              'rows' => $rows,
            ));
            $vars[$location . '_widget_rendered'] .= $vars[$widget_id . '_' . $location];
          }
        }
      }
    }

    // Process Slideshow.
    $slides = theme(views_theme_functions($main_frame_module . '_main_frame', $view, $view->display[$view->current_display]), array(
      'vss_id' => $vss_id,
      'view' => $view,
      'settings' => $settings,
      'rows' => $rows,
      'options' => $options,
    ));
    $vars['slideshow'] = theme(views_theme_functions('views_slideshow_main_section', $view, $view->display[$view->current_display]), array(
      'vss_id' => $vss_id,
      'slides' => $slides,
      'plugin' => $main_frame_module,
    ));
  }
}