Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 CreditAttribution: minorOffense commentedCan you provide this as a patch to test out?
Comment #2
TelFiRE CreditAttribution: TelFiRE commentedDid you make sure in your view field that you had the multiple values in one field unchecked?
Comment #3
Jackinloadup CreditAttribution: 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 CreditAttribution: minorOffense commentedMoving to the 2.x branch
Comment #5
priapurnama CreditAttribution: priapurnama commentedThis still happens and the fix works like a charm. Awesome.
Comment #6
minorOffense CreditAttribution: minorOffense commentedThis should be fixed in 2.x now.
Comment #7.0
(not verified) CreditAttribution: commentedlet see if this looks better...