Simple snippet to only output the first image of an imagefield in a view and show the rest of the gallery in the photoswipe overlay.
Hint: Don't forget to add the photoswipe-gallery class on the field wrapper in views settings: http://cgit.drupalcode.org/photoswipe/tree/README.txt?h=7.x-2.x
/**
* Implements hook_views_pre_render().
*/
function MYMODULE_views_pre_render(&$view) {
// #webksde#JP20171215: Only show the first image and the rest only in the gallery
if ($view->name == 'YOUR_VIEW_NAME') {
if(!empty($view->result)){
foreach($view->result as $row_key => $row){
if(!empty($row->field_field_galerie)){
foreach($row->field_field_galerie as $galerie_item_key => $galerie_item){
if($galerie_item_key > 0){
$item = $galerie_item['rendered']['#item'];
$settings = $galerie_item['rendered']['#display_settings'];
$alt = !empty($item['alt']) ? $item['alt'] : '';
$title = !empty($item['title']) ? $item['title'] : '';
if (empty($alt) && !empty($item['field_file_image_alt_text'][LANGUAGE_NONE])) {
$alt = $item['field_file_image_alt_text'][LANGUAGE_NONE][0]['value'];
}
if (empty($title) && !empty($item['field_file_image_title_text'][LANGUAGE_NONE])) {
$title = $item['field_file_image_title_text'][LANGUAGE_NONE][0]['value'];
}
if ($style_name = $settings['photoswipe_image_style']) {
$path = image_style_url($style_name, $item['uri']);
$dimensions = array(
'width' => $item['width'],
'height' => $item['height'],
);
image_style_transform_dimensions($style_name, $dimensions);
}
else {
$path = file_create_url($item['uri']);
}
$view->result[$row_key]->field_field_galerie[$galerie_item_key]['rendered'] = array(
'#theme' => 'link',
'#text' => '',
'#path' => $path,
'#options' => array(
'html' => TRUE,
'attributes' => array(
'class' => 'photoswipe',
'data-size' => $item['width'] . 'x' . $item['height'],
'data-overlay-title' => $item['title'],
)
)
);
}
}
}
}
}
}
}
?>