You are here

function template_preprocess_slider_pro_view in Slider Pro 7

Display a view as a Slider Pro style.

File

./slider_pro.module, line 109

Code

function template_preprocess_slider_pro_view(&$vars) {
  $view = $vars['view'];
  $result = $vars['rows'];
  $vars['rows'] = array();

  // Get values from options form.
  $options = $view->style_plugin->options['slider_pro'];

  // Get fields.
  $fields =& $view->field;

  // Render fields with view style plugin.
  $handler = $view->style_plugin;
  $rendered_rows = $handler
    ->render_fields($result);

  // Overwrite $vars['rows'] with rendered fields and thumbnails.
  $fields_on_slide = array_filter($options['fields_on_slide']);
  $fields_on_thumbnail = $vars['use_thumbnails'] ? array_filter($options['thumbnails']['fields_on_thumbs']) : array();

  // Store use_thumbnails boolean.
  $vars['use_thumbnails'] = $options['thumbnails']['thumbnails_position'];
  foreach ($rendered_rows as $num => $row) {
    $rendered_slide = array();
    $rendered_thumb = array();
    $rendered_layers = array();
    foreach ($row as $field_name => $field) {

      // Check if fields has to be displayed on slide.
      if (in_array($field_name, $fields_on_slide)) {
        $rendered_slide[$field_name] = $field;
      }

      // Check if fields has to be displayed on thumb.
      if (in_array($field_name, $fields_on_thumbnail) && $vars['use_thumbnails']) {
        $rendered_thumb[$field_name] = $field;
      }

      // Check if any layers have to be rendered.
      $layers = !empty($options['layers']['table']) ? array_values($options['layers']['table']) : array();
      foreach ($layers as $key => $layer) {
        $render_layer = FALSE;
        $layer_fields = array_filter($layer['fields']);
        if (!empty($layer_fields)) {

          // A layer is configured.
          $render_layer = TRUE;
          if (in_array($field_name, $layer_fields)) {

            // Field has to be on layer.
            $rendered_layers[$key]['fields'][$field_name] = $field;
          }
        }
        if ($render_layer) {
          $rendered_layers[$key]['background'] = $layer['background'];
          $rendered_layers[$key]['data_position'] = $layer['data_position'];
          $rendered_layers[$key]['data_show_transition'] = $layer['data_show_transition'];
          $rendered_layers[$key]['data_hide_transition'] = $layer['data_hide_transition'];
          $rendered_layers[$key]['data_show_delay'] = !empty($layer['data_show_delay']) ? $layer['data_show_delay'] : 500;
          $rendered_layers[$key]['data_stay_duration'] = !empty($layer['data_stay_duration']) ? $layer['data_stay_duration'] : 500;
        }
      }

      // Add classes to fields.
      $vars['field_classes'][$field_name][$num] = array(
        drupal_clean_css_identifier($field_name),
      );
      $classes = $fields[$field_name]
        ->element_classes($num);
      if (!empty($classes)) {
        $vars['field_classes'][$field_name][$num][] = $classes;
      }

      // Store field labels.
      $vars['field_labels'][$field_name][$num] = $fields[$field_name]
        ->label();
    }
    $vars['rows'][$num]['slide'] = $rendered_slide;
    $vars['rows'][$num]['thumb'] = $rendered_thumb;
    $vars['rows'][$num]['layers'] = $rendered_layers;
  }

  // Set unique id, so that multiple instances on one page can be created.
  $unique_id = uniqid();
  $vars['id'] = $unique_id;

  // Add libraries and settings.
  $option_set = _slider_pro_build_option_set($options);
  slider_pro_add($unique_id, $option_set);
}