Closed (fixed)
Project:
Flex Slider
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Jul 2012 at 16:36 UTC
Updated:
13 Sep 2013 at 00:55 UTC
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
Comment #1
minoroffense commentedCan you provide this as a patch to test out?
Comment #2
TelFiRE commentedDid you make sure in your view field that you had the multiple values in one field unchecked?
Comment #3
Jackinloadup commentedTelFiRE: Thats a great point unless OP wants to show a view with multiple flexsliders. Say one per node for a blog list view.
Comment #4
minoroffense commentedMoving to the 2.x branch
Comment #5
priapurnama commentedThis still happens and the fix works like a charm. Awesome.
Comment #6
minoroffense commentedThis should be fixed in 2.x now.
Comment #7.0
(not verified) commentedlet see if this looks better...