public function JuiceboxFormatter::styleImageSrcData in Juicebox HTML5 Responsive Image Galleries 8.2
Same name and namespace in other branches
- 8.3 src/JuiceboxFormatter.php \Drupal\juicebox\JuiceboxFormatter::styleImageSrcData()
Utility to extract image source data.
Extract in an array structure that can be used when adding a new image to the gallery.
Parameters
Drupal\file\FileInterface $image_file: A file entity representing the main image.
string $image_style: The Drupal image style to apply to the main image.
Drupal\file\FileInterface $thumb_file: A file entity representing the thumbnail image.
string $thumb_style: The Drupal image style to apply to the thumbnail image.
array $settings: An associative array of gallery-specific settings.
Return value
array An associative array of image source URLs that's ready to be added to a Juicebox gallery, including:
- imageURL: URL to the full image to display.
- thumbURL: URL to the thumbnail to display for the image.
- linkURL: The Juicebox "link URL" value for the image.
- linkTarget: 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 JuiceboxFormatterInterface::styleImageSrcData
File
- src/
JuiceboxFormatter.php, line 252
Class
- JuiceboxFormatter
- Class to define a Drupal service with common formatter methods.
Namespace
Drupal\juiceboxCode
public function styleImageSrcData(FileInterface $image_file, $image_style, FileInterface $thumb_file, $thumb_style, array $settings) {
$check_incompatible = !empty($settings['incompatible_file_action']);
$src_data = [];
// Style the main item.
$src_data = $this
->styleImage($image_file, $image_style, $check_incompatible);
// Set thumb data and add it to the source info.
$src_data['thumbURL'] = '';
if (!$src_data['juicebox_compatible'] && $image_file
->id() == $thumb_file
->id()) {
$src_data['thumbURL'] = $src_data['imageURL'];
}
else {
$thumb_image_data = $this
->styleImage($thumb_file, $thumb_style, $check_incompatible);
$src_data['thumbURL'] = $thumb_image_data['imageURL'];
}
// Check if the linkURL should be customized based on settings.
$src_data['linkURL'] = $src_data['unstyled_src'];
if ($src_data['juicebox_compatible'] && !empty($settings['linkurl_source']) && $settings['linkurl_source'] == 'image_styled') {
$src_data['linkURL'] = $src_data['imageURL'];
}
// Set the link target directly from the gallery settings.
$src_data['linkTarget'] = !empty($settings['linkurl_target']) ? $settings['linkurl_target'] : '_blank';
return $src_data;
}