You are here

function juicebox_field_build_gallery in Juicebox HTML5 Responsive Image Galleries 7.2

Utility to build a Juicebox gallery based on field formatter data.

Parameters

JuiceboxGalleryWrapperInterface $juicebox: A juicebox object ready to be manipulated into a gallery.

array $items: An array for file field items that have been loaded to represent individual gallery images.

2 calls to juicebox_field_build_gallery()
JuiceboxXmlField::getXml in plugins/JuiceboxXmlField.inc
Get the XML based on loaded data.
juicebox_field_formatter_view in includes/juicebox.field.inc
Implements hook_field_formatter_view().

File

includes/juicebox.field.inc, line 252
Contains all hooks and related methods for the juicebox_formatter field formatter.

Code

function juicebox_field_build_gallery(JuiceboxGalleryDrupalInterface $juicebox, $items) {
  $settings = $juicebox
    ->getSettings();
  foreach ($items as $id => $item) {

    // Calculate the source data that Juicebox requires.
    $src_data = $juicebox
      ->styleImageSrcData($item, $settings['image_style'], $item, $settings['thumb_style']);

    // Short-circut this iteration if skipping an incompatible file.
    if (!$src_data['juicebox_compatible'] && $settings['incompatible_file_action'] == 'skip') {
      continue;
    }

    // Set the image title. If we have an incompatible file and are configured
    // to show a link, set the title text as the link.
    if (!$src_data['juicebox_compatible'] && $settings['incompatible_file_action'] == 'show_icon_and_link') {
      $anchor = !empty($item['description']) ? $item['description'] : $item['filename'];
      $title = l($anchor, $src_data['link_url']);
    }
    else {
      $title = _juicebox_field_get_text($item, $settings['title_source']);
    }

    // Set the image caption.
    $caption = _juicebox_field_get_text($item, $settings['caption_source']);

    // Add this image to the gallery.
    $juicebox
      ->addImage($src_data, $title, $caption);
  }

  // Run common build tasks.
  $juicebox
    ->runCommonBuild();
}