function juicebox_build_gallery_data_from_entity_field in Juicebox HTML5 Responsive Image Galleries 7
Generate data for a Juicebox gallery from an entity image field.
Parameters
array $items: A list of image items from an image field that is part of an entity. This will typically be constructed with field_get_items().
array $settings: A associative array of field formatter settings specific to this gallery display.
object $entity: The full entity object that the field we are rendering as a gallery was sourced from.
string $xml_path: The path to this gallery's XML (can be used as a unique gallery ID).
Return value
array An associative array containing all the content and configuration data needed to build a Juicebox gallery and XML.
2 calls to juicebox_build_gallery_data_from_entity_field()
- juicebox_field_formatter_view in ./
juicebox.module - Implements hook_field_formatter_view().
- juicebox_page_xml in ./
juicebox.module - Menu callback: generate Juicebox XML.
File
- ./
juicebox.module, line 301 - Provides Drupal integration with the Juicebox library.
Code
function juicebox_build_gallery_data_from_entity_field($items, $settings, $entity, $xml_path) {
// Prepare images
$images = array();
foreach ($items as $id => $item) {
$unstyled_image_src = file_create_url($item['uri']);
// Get the main image source.
$image_src = $unstyled_image_src;
if (!empty($settings['image_style'])) {
$image_src = image_style_url($settings['image_style'], $item['uri']);
}
// Get thumb source.
$thumb_src = $unstyled_image_src;
if (!empty($settings['thumb_style'])) {
$thumb_src = image_style_url($settings['thumb_style'], $item['uri']);
}
// Get the image title.
$title = '';
if (!empty($item[$settings['title_source']])) {
$title = check_markup($item[$settings['title_source']]);
}
// Get the image caption.
$caption = '';
if (!empty($item[$settings['caption_source']])) {
$caption = check_markup($item[$settings['caption_source']]);
}
// Filter the image title and caption markup.
if (!empty($settings['apply_markup_filter'])) {
$title = _juicebox_filter_markup($title);
$caption = _juicebox_filter_markup($caption);
}
// Get the linkURL.
$image_link_src = $unstyled_image_src;
if (!empty($settings['linkurl_source'])) {
$image_link_src = $image_src;
}
// Add each image to the data.
$images[$id]['image_src'] = $image_src;
$images[$id]['image_link_src'] = $image_link_src;
$images[$id]['thumb_src'] = $thumb_src;
$images[$id]['title'] = $title;
$images[$id]['caption'] = $caption;
$images[$id]['linkurl_target'] = $settings['linkurl_target'];
}
// Get the Juicebox library-specific options.
$jlib_options = _juicebox_get_lib_options($settings);
$data = array(
'jlib_options' => $jlib_options,
'images' => $images,
);
// Allow other modules to alter the data we are using to build the gallery.
$source_info = array(
'xml_path' => $xml_path,
'source' => $entity,
);
drupal_alter('juicebox_gallery_data', $data, $settings, $source_info);
// Make sure all Juicebox library configuration keys are lowercase to make
// future key lookups easier.
$data['jlib_options'] = array_change_key_case($data['jlib_options']);
return $data;
}