function _slick_build_fc_overlay in Slick Carousel 7.2
Build the managed overlays: image, video, audio or nested slicks.
1 call to _slick_build_fc_overlay()
- slick_format_field_collection in includes/
slick.field_collection.inc - Formats Field collection data.
File
- includes/
slick.field_collection.inc, line 136 - Fields formatter for the Slick and Field collection integration.
Code
function _slick_build_fc_overlay(&$settings, $wrapper, $options = array()) {
$elements = array();
$items = $wrapper->{$settings['slide_overlay']}
->value();
$renderables = $options['fields'][$settings['slide_overlay']];
$entity_id = $settings['entity_id'];
$entity_type = $renderables['#entity_type'];
$bundle = $renderables['#bundle'];
$field_name = $renderables['#field_name'];
$nested_style = empty($settings['nested_style']) ? $settings['image_style'] : $settings['nested_style'];
$css_id = slick_html_id("slick-nested-{$entity_type}-{$entity_id}-{$bundle}-{$field_name}");
$settings['picture_ready'] = FALSE;
$overlays = array();
$overset = array(
'current_display' => 'overlay',
'image_style' => $nested_style,
);
$overset = array_merge($settings, $overset);
$overset_global = $overset;
$dimensions = array();
if (!empty($nested_style)) {
$image = array();
$dimensions = slick_get_dimensions($image, $nested_style);
}
switch ($renderables['#field_type']) {
case 'image':
case 'file':
foreach ($items as $i => $item) {
// Prevents edge case EntityMalformedException: Missing bundle property.
if (!isset($item['uri'])) {
continue;
}
$media = $dimensions;
$overset['delta'] = $i;
if ($renderables['#field_type'] == 'file') {
$file = (object) $item;
// Needed settings: type scheme image_style uri view_mode.
// Extracts media data for: embed_url, box_height, box_width, uri.
slick_extract_media_data($overset, $media, $file);
}
$overlays[$i]['item'] = $item;
$overlays[$i]['media'] = $media;
$overlays[$i]['settings'] = $overset;
}
break;
case 'atom_reference':
foreach ($items as $i => $item) {
$sid = $item->sid;
$atom = scald_atom_load($sid);
$base_id = $item->base_id;
$langcode = isset($item->language) ? $item->language : $options['langcode'];
$thumbnail = isset($item->scald_thumbnail[$langcode][0]) ? $item->scald_thumbnail[$langcode][0] : array();
$media = $dimensions;
$media['scheme'] = $item->provider;
$providers = array(
'scald_youtube',
'scald_vimeo',
'scald_dailymotion',
'video',
);
$overset['delta'] = $i;
if (in_array($item->provider, $providers)) {
$media['media_id'] = $base_id;
if (strpos($item->provider, 'scald_') !== FALSE) {
$media['scheme'] = substr($item->provider, -6);
}
}
$media['embed_url'] = '';
switch ($item->provider) {
case 'scald_youtube':
$media['embed_url'] = '//www.youtube.com/embed/' . $base_id;
break;
case 'scald_vimeo':
$media['embed_url'] = '//player.vimeo.com/video/' . $base_id;
break;
case 'scald_dailymotion':
$media['embed_url'] = '//www.dailymotion.com/embed/video/' . $base_id;
break;
case 'video':
$media['embed_url'] = $atom->file_source;
break;
default:
break;
}
$media['uri'] = $atom->file_source;
$media['type'] = $item->type == 'slick' ? 'image' : $item->type;
$overset['sid'] = $sid;
$overlays[$i]['item'] = $thumbnail;
$overlays[$i]['media'] = $media;
$overlays[$i]['settings'] = $overset;
}
break;
default:
break;
}
$slides = $overlays;
// Build the overlays: single static image/audio/video, or nested slicks.
// Managed overlays with known formatters are nested slicks, or static.
if ($slides) {
$nested_settings = array(
'count' => count($slides),
'id' => $css_id,
'lightbox_ready' => strpos($settings['media_switch'], 'box') !== FALSE,
'optionset' => $options['nested_name'],
'picture' => FALSE,
'picture_ready' => FALSE,
'attributes' => array(
'class' => array(
'slick--nested',
),
),
);
$nested_settings = array_merge($overset_global, $nested_settings);
$nested_settings_global = $nested_settings;
// Process individual slick overlay.
$element = $js = array();
foreach ($slides as $delta => $item) {
$slide = array();
$media = $item['media'];
$item_settings = array_merge($item['settings'], $nested_settings);
$item_settings['delta'] = $delta;
if (empty($settings['nested_slick'])) {
$delta = 0;
}
// Image with picture, lazyLoad, and lightbox supports.
$slide['slide'] = slick_get_image($item_settings, $media, $item['item']);
$slide['settings'] = $item_settings;
$element[$delta] = $slide;
unset($slide);
}
// Build the nested slicks.
if (!empty($settings['nested_slick'])) {
$attach['attach_media'] = $settings['media_switch'] == 'iframe-switch';
$elements = slick_build($element, $js, $nested_settings_global, $attach, $css_id, $options['nested_set']);
}
else {
// Otherwise cares for a single overlay item to not break small layout.
$elements = $element[0];
}
}
return $elements;
}