view sites/all/modules/flexslider/flexslider_views/flexslider_views.module @ 2:b74b41bb73f0

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents
children
line wrap: on
line source
<?php

/**
 * @file
 * Adds Views plugins for FlexSlider
 *
 * @author Mathew Winstone <mwinstone@coldfrontlabs.ca>
 */

/**
 * Implements hook_views_api().
 */
function flexslider_views_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Add a preprocessor for flexslider for dealing with FlexSlider views
 */
function flexslider_views_preprocess_flexslider(&$vars) {
  // Only run the preprocessor if it is a view
  if (!empty($vars['view'])) {
    // Prepare all data to be passed to theme_flexslider().
    $items = array();
    $view = $vars['view'];
    $settings = array();
    $settings['optionset'] = $vars['options']['optionset'];

    $row_plugin = $view->style_plugin->row_plugin;

    foreach ($vars['rows'] as $id => $row) {
      // Render the row into a slide
      $view->row_index = $id;
      $item['slide'] = $row_plugin->render($row);

      $items[] = $item;
    }

    // Add the slide items to the variables
    $vars['items'] = $items;

    // Add the attributes
    $settings['attributes']['id'] = $vars['options']['id'];

    // Reset the options to the processed values
    $vars['settings'] = $settings;
  }
}