function bxslider_field_formatter_view in BxSlider 7
Implements hook_field_formatter_view().
File
- ./
bxslider.module, line 1082 - Fields integration with BxSlider.
Code
function bxslider_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = array();
$settings['slider_id'] = $instance['field_name'];
if (count($items) > 0) {
if ($display['type'] == 'bxslider') {
$method2_items = '';
foreach ($items as $key => $item) {
$slide_item['item'] = $item;
// Prepare variables for theme_image_style.
$img = array(
'path' => $item['uri'],
'style_name' => $display['settings']['image_style'],
'alt' => $item['alt'],
'title' => $item['title'],
);
if (!empty($display['settings']['image_style'])) {
// Here, theme('image_style', ...) isn't used, because there are
// defined "height" and "width" attributes and the slider become not
// responsive.
$img['path'] = image_style_url($display['settings']['image_style'], $item['uri']);
}
$slide_item['slide'] = theme('image', $img);
// If using Colorbox.
if ($display['settings']['colorbox']['enable']) {
// Used for combination of elements together for a gallery.
$slide_item['item']['rel'] = $field["id"];
$slide_item['slide'] = theme('bxslider_colorbox', array(
'slide_item' => $slide_item,
'settings' => $display['settings'],
));
}
if (isset($display['settings']['pager']['pagerCustom_type']) && ($display['settings']['pager']['pagerCustom_type'] == 'thumbnail_pager_method1' || $display['settings']['pager']['pagerCustom_type'] == 'thumbnail_pager_method2')) {
// Prepare variables for theme_image_style.
$img['style_name'] = empty($display['settings']['pager']['pagerCustom_image_style']) ? 'thumbnail' : $display['settings']['pager']['pagerCustom_image_style'];
$slide_item['slide_pagerCustom'] = theme('image_style', $img);
if ($display['settings']['pager']['pagerCustom_type'] == 'thumbnail_pager_method2') {
$method2_items .= "case " . $key . ": return '" . $slide_item['slide_pagerCustom'] . "';";
}
}
$items[$key] = $slide_item;
}
if (isset($display['settings']['pager']['pagerCustom_type']) && $display['settings']['pager']['pagerCustom_type'] == 'thumbnail_pager_method1') {
$display['settings']['pager']['pagerCustom'] = '#bxslide-pager-th';
}
$method2 = array();
if (isset($display['settings']['pager']['pagerCustom_type']) && $display['settings']['pager']['pagerCustom_type'] == 'thumbnail_pager_method2') {
$method2 = array(
'buildPager' => "switch(slideIndex){" . $method2_items . "}",
);
}
$settings['slider_settings'] = array_merge($display['settings']['general'], $display['settings']['pager'], $display['settings']['controls'], $display['settings']['auto'], $display['settings']['carousel'], $method2);
$element = array(
'#theme' => 'bxslider',
'#items' => $items,
'#settings' => $settings,
);
}
elseif ($display['type'] == 'bxslider_ths') {
foreach ($items as $key => $item) {
$slide_item['item'] = $item;
// Prepare variables for theme_image.
$img = array(
'path' => $item['uri'],
'style_name' => $display['settings']['image_style'],
'alt' => $item['alt'],
'title' => $item['title'],
);
if (!empty($display['settings']['image_style'])) {
// Here, theme('image_style', ...) isn't used, because there are
// defined "height" and "width" attributes and the slider become
// not responsive.
$img['path'] = image_style_url($display['settings']['image_style'], $item['uri']);
}
$slide_item['slide'] = theme('image', $img);
// If using Colorbox.
if ($display['settings']['colorbox']['enable']) {
// Used for combination of elements together for a gallery.
$slide_item['item']['rel'] = $field["id"];
$slide_item['slide'] = theme('bxslider_colorbox', array(
'slide_item' => $slide_item,
'settings' => $display['settings'],
));
}
$items[$key] = $slide_item;
// Generate thumbnails.
$thumbnail_style = empty($display['settings']['thumbnail_slider']['thumbnail_style']) ? 'thumbnail' : $display['settings']['thumbnail_slider']['thumbnail_style'];
$thumbnail_item = array();
$img['path'] = image_style_url($thumbnail_style, $item['uri']);
// Here, theme('image_style', ...) isn't used, because there are defined
// "height" and "width" attributes and the slider become not responsive.
$thumbnail_item['thumbnail'] = theme('image', $img);
// Prepare variables for theme_image_style.
$thumbnail_item['thumbnail_item']['path'] = $img['path'];
$thumbnail_item['thumbnail_item']['style_name'] = $thumbnail_style;
$thumbnail_item['thumbnail_item']['alt'] = $item['alt'];
$thumbnail_item['thumbnail_item']['title'] = $item['title'];
$thumbnail_items[$key] = $thumbnail_item;
// Fill the "slideWidth" parameter with the width defined
// by image's style.
$thumbnail_info = image_get_info($img['path']);
$display['settings']['thumbnail_slider']['carousel']['slideWidth'] = $thumbnail_info['width'];
}
$settings['slider_settings'] = array_merge($display['settings']['general'], $display['settings']['pager'], $display['settings']['controls'], $display['settings']['auto'], $display['settings']['carousel']);
$settings['thumbnail_slider_settings'] = array_merge($display['settings']['thumbnail_slider']['general'], $display['settings']['thumbnail_slider']['pager'], $display['settings']['thumbnail_slider']['controls'], $display['settings']['thumbnail_slider']['auto'], $display['settings']['thumbnail_slider']['carousel']);
$element = array(
'#theme' => 'bxslider_ths',
'#items' => $items,
'#thumbnail_items' => $thumbnail_items,
'#settings' => $settings,
);
}
}
return $element;
}