protected function JuiceboxDisplayStyle::buildGallery in Juicebox HTML5 Responsive Image Galleries 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/views/style/JuiceboxDisplayStyle.php \Drupal\juicebox\Plugin\views\style\JuiceboxDisplayStyle::buildGallery()
Build the gallery based on loaded Drupal views data.
Parameters
Drupal\juicebox\JuiceboxGalleryInterface $gallery: An initialized Juicebox gallery object.
1 call to JuiceboxDisplayStyle::buildGallery()
- JuiceboxDisplayStyle::render in src/
Plugin/ views/ style/ JuiceboxDisplayStyle.php - Render the display in this style.
File
- src/
Plugin/ views/ style/ JuiceboxDisplayStyle.php, line 276
Class
- JuiceboxDisplayStyle
- Plugin implementation of the 'juicebox' display style.
Namespace
Drupal\juicebox\Plugin\views\styleCode
protected function buildGallery(JuiceboxGalleryInterface $gallery) {
$view = $this->view;
$settings = $this->options;
// Populate $this->rendered_fields.
$this
->renderFields($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'], $settings);
// 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($this->rendered_fields[$row_index][$settings['linkurl_source']])) {
$src_data['linkURL'] = (string) $this->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 = $this->linkGenerator
->generate($anchor, Url::fromUri($src_data['linkURL']));
}
elseif (!empty($settings['title_field']) && !empty($this->rendered_fields[$row_index][$settings['title_field']])) {
$title = (string) $this->rendered_fields[$row_index][$settings['title_field']];
}
// Set the image caption.
$caption = '';
if (!empty($settings['caption_field']) && !empty($this->rendered_fields[$row_index][$settings['caption_field']])) {
$caption = (string) $this->rendered_fields[$row_index][$settings['caption_field']];
}
// Add this image to the gallery.
$gallery
->addImage($src_data, $title, $caption);
}
if ($settings['show_title']) {
$gallery
->addOption('gallerytitle', Html::escape($view
->getTitle()));
}
// Run common build tasks.
$this->juicebox
->runCommonBuild($gallery, $settings, $view);
}