public function JuiceboxFormatterViewsStyle::buildGallery in Juicebox HTML5 Responsive Image Galleries 7.2
Build the gallery based on loaded Drupal views data.
1 call to JuiceboxFormatterViewsStyle::buildGallery()
- JuiceboxFormatterViewsStyle::render in plugins/
JuiceboxFormatterViewsStyle.inc - Render the view page display.
File
- plugins/
JuiceboxFormatterViewsStyle.inc, line 211 - Contains the Juicebox views style plugin.
Class
- JuiceboxFormatterViewsStyle
- Style plugin to render each item in a views list.
Code
public function buildGallery() {
$view = $this->view;
$settings = $this->options;
$rendered_fields = $this
->render_fields($view->result);
// Get all row image data in the format of Drupal file field items.
$image_items = $thumb_items = $this
->getItems($settings['image_field']);
if ($settings['image_field'] != $settings['thumb_field']) {
$thumb_items = $this
->getItems($settings['thumb_field']);
}
// Iterate through each view row and calculate the gallery-specific details.
foreach ($image_items as $row_index => $image_item) {
// Make sure each main image has a thumb item.
$thumb_item = !empty($thumb_items[$row_index]) ? $thumb_items[$row_index] : $image_item;
// Calculate the source data that Juicebox requires.
$src_data = $this->juicebox
->styleImageSrcData($image_item, $settings['image_field_style'], $thumb_item, $settings['thumb_field_style']);
// Short-circut this iteration if skipping an incompatible file.
if (!$src_data['juicebox_compatible'] && $settings['incompatible_file_action'] == 'skip') {
continue;
}
// Check if the linkURL should be customized based on view settings.
if (!empty($settings['linkurl_source']) && !empty($rendered_fields[$row_index][$settings['linkurl_source']])) {
$src_data['link_url'] = $rendered_fields[$row_index][$settings['linkurl_source']];
}
// Set the image title.
$title = '';
// If we have an incompatible file the title may need special handeling.
if (!$src_data['juicebox_compatible'] && $settings['incompatible_file_action'] == 'show_icon_and_link') {
$anchor = !empty($image_item['description']) ? $image_item['description'] : $image_item['filename'];
$title = l($anchor, $src_data['link_url']);
}
elseif (!empty($settings['title_field']) && !empty($rendered_fields[$row_index][$settings['title_field']])) {
$title = $rendered_fields[$row_index][$settings['title_field']];
}
// Set the image caption.
$caption = '';
if (!empty($settings['caption_field']) && !empty($rendered_fields[$row_index][$settings['caption_field']])) {
$caption = $rendered_fields[$row_index][$settings['caption_field']];
}
// Add this image to the gallery.
$this->juicebox
->addImage($src_data, $title, $caption);
}
if ($settings['show_title']) {
$this->juicebox
->addOption('gallerytitle', check_plain($view
->get_title()));
}
// Run common build tasks.
$this->juicebox
->runCommonBuild();
}