Skip to content

Instantly share code, notes, and snippets.

@init90
Last active May 4, 2018 19:35
Show Gist options
  • Save init90/64e918a0a71dca0de1a812f21e2c2e73 to your computer and use it in GitHub Desktop.
Save init90/64e918a0a71dca0de1a812f21e2c2e73 to your computer and use it in GitHub Desktop.
Drupal 7. Preproccess colorbox images.
/**
* Implements template_preprocess_field
*/
function THEME_preprocess_field(&$vars) {
// Display first image in colorbox gallery preview.
if (isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'field_product_image') {
if (isset($vars['items'][0]['#theme']) && ($vars['items'][0]['#theme'] == 'colorbox_image_formatter')) {
$first_photo_copy = $vars['items'][0];
// Disable copy image in gallery, use only for preview.
$first_photo_copy['#display_settings']['colorbox_gallery'] = 'none';
// Add copy image to colorbox gallery.
array_push($vars['items'], $first_photo_copy);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment