You are here

public function JuiceboxGalleryDrupal::styleImageSrcData in Juicebox HTML5 Responsive Image Galleries 7.2

Utility to extract image source data in an array structure that can be used when adding a new image to the gallery.

Parameters

array $image_item: An associative array of file field item data for the main image.

string $image_style: The Drupal image style to apply to the main image.

array $thumb_item: An associative array of file field item data for the thumbnail image.

string $thumb_style: The Drupal image style to apply to the thumbnail image.

Return value

array An associative array of image source URLs that's ready to be added to a Juicebox gallery, including:

  • image_url: URL to the full image to display.
  • image_url_small: URL to the full image to display in small screen mode. Only included if $image_style = juicebox_multisize.
  • image_url_large: URL to the full image to display in large screen mode. Only included if $image_style = juicebox_multisize.
  • thumb_url: URL to the thumbnail to display for the image.
  • link_url: The Juicebox "link URL" value for the image.
  • link_target: The browser target value to use when following a link URL.
  • juicebox_compatible: Boolean indicating if the raw source file for the main image is directly compatible with the Juicebox library.

Overrides JuiceboxGalleryDrupalInterface::styleImageSrcData

File

includes/JuiceboxGalleryDrupal.inc, line 164
Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.

Class

JuiceboxGalleryDrupal
Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.

Code

public function styleImageSrcData($image_item, $image_style, $thumb_item, $thumb_style) {
  $settings = $this->settings;

  // Make sure that we have proper file field items to work with.
  if (!isset($image_item['fid']) || !isset($thumb_item['fid'])) {
    throw new Exception(t('Invalid image or thumbnail item detected while extracting Juicebox gallery source information.'));
  }
  $check_incompatible = !empty($settings['incompatible_file_action']);
  $src_data = array();

  // Style the main item.
  $this
    ->styleImage($image_item, $image_style, $check_incompatible);
  $src_data = $image_item['juicebox_src_data'];

  // Style the thumb.
  if (!$image_item['juicebox_compatible'] && $image_item['fid'] == $thumb_item['fid']) {
    $src_data['thumb_url'] = $src_data['image_url'];
  }
  else {
    $this
      ->styleImage($thumb_item, $thumb_style, $check_incompatible);
    $src_data['thumb_url'] = $thumb_item['juicebox_src_data']['image_url'];
  }

  // Check if the linkURL should be customized based on settings.
  $src_data['link_url'] = $image_item['unstyled_src'];
  if ($image_item['juicebox_compatible'] && !empty($settings['linkurl_source']) && $settings['linkurl_source'] == 'image_styled') {
    $src_data['link_url'] = $src_data['image_url'];
  }

  // Set the link target directly from the gallery settings.
  $src_data['link_target'] = !empty($settings['linkurl_target']) ? $settings['linkurl_target'] : '_blank';

  // Also set a flag for incompatible files.
  $src_data['juicebox_compatible'] = $image_item['juicebox_compatible'];
  return $src_data;
}