So I couldn't get Flexslider to display a multi-value image field through the view correctly. It just kept giving me 3 of the same image. This code look ugly but I was able to get this working. How can I improve this hack? I had to do this pretty quickly, btw.

function theme_views_view_flexslider($vars) {
  $items = array();

  $view = $vars['view'];
  $img_field_name = $vars['img_field_name'];

  // if we have a multivalue field, lets roll this stuff up
  if (count($vars['rows'][0]->_field_data[$view->base_field]['entity']->{$img_field_name}[LANGUAGE_NONE]) > 1) {
    foreach ($vars['rows'] as $key=>$row) {
      $item = $row->_field_data[$view->base_field]['entity']->{$img_field_name}[LANGUAGE_NONE][$key];
      $items[] = $item;
    }
  }
  else {
    foreach ($vars['rows'] as $row) {
      // Can't assume the field has the same language as the Entity that
      // contains it
      // $lang = $row->_field_data[$view->base_field]['entity']->language;
      // omit rows without image field.
      if (!isset($row->_field_data[$view->base_field]['entity']->{$img_field_name})) {
        continue;
      }
      // Fields in core don't inherit their containing language by default.
      // Assume LANGUAGE_NONE until a better solution comes along
      $item = $row->_field_data[$view->base_field]['entity']->{$img_field_name}[LANGUAGE_NONE][0];
      $items[] = $item;
    }
  }


  return theme('flexslider_container', array(
    'items' => $items,
    'settings' => $vars['options'],
  ));
}

Comments

minorOffense’s picture

Category: support » feature
Status: Active » Needs work

Can you provide this as a patch to test out?

TelFiRE’s picture

Did you make sure in your view field that you had the multiple values in one field unchecked?

Jackinloadup’s picture

TelFiRE: Thats a great point unless OP wants to show a view with multiple flexsliders. Say one per node for a blog list view.

minorOffense’s picture

Version: 7.x-1.0-rc3 » 7.x-2.x-dev

Moving to the 2.x branch

priapurnama’s picture

This still happens and the fix works like a charm. Awesome.

minorOffense’s picture

Status: Needs work » Fixed

This should be fixed in 2.x now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

let see if this looks better...