You are here

function template_preprocess_media_gallery_media_item_thumbnail in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.theme.inc \template_preprocess_media_gallery_media_item_thumbnail()

Template preprocess function for displaying a media item (entity) as a thumbnail on the gallery page.

File

./media_gallery.theme.inc, line 108
Media Gallery Theming

Code

function template_preprocess_media_gallery_media_item_thumbnail(&$variables) {
  $element = $variables['element'];

  // Attach the colorbox javascript if the format calls for it.
  $format = $element['#media_gallery_entity']->media_gallery_format[LANGUAGE_NONE][0]['value'];
  $lightbox = is_numeric(strpos($format, 'lightbox')) ? TRUE : FALSE;
  if ($lightbox) {
    $element['file']['#attached']['js'][] = drupal_get_path('module', 'media_gallery') . '/colorbox-display.js';
    $element['file']['#attached']['js'][] = drupal_get_path('module', 'media_gallery') . '/colorbox-behavior.js';
    $element['file']['#attached']['library'][] = array(
      'media_gallery',
      'colorbox',
    );
  }

  // Get the rendered file without annoying DIV wrappers.
  $element['file'] = array(
    '#theme' => 'media_gallery_file_field_inline',
    '0' => $element['file'],
  );
  $image = drupal_render($element['file']);
  $gallery_id = $element['#media_gallery_entity']->nid;
  $media_id = $element['#file']->fid;

  // Add a class that is a more targeted version of what template_preprocess()
  // automatically adds for this theme hook, to enable per-type (e.g., video vs.
  // image) styling.
  $variables['classes_array'][] = drupal_html_class('media_gallery_media_item_thumbnail_' . $element['#file']->type);

  // Add a class for the wrapper.
  $variables['classes_array'][] = 'media-gallery-item-wrapper';

  // Create an array of variables to be added to the main thumbnail link.
  $link_vars = array();
  $link_vars['image'] = $image;
  $link_vars['link_path'] = "media-gallery/detail/{$gallery_id}/{$media_id}";
  $link_vars['classes'] = $lightbox ? array(
    'media-gallery-thumb',
    'cbEnabled',
  ) : array(
    'media-gallery-thumb',
  );
  $link_vars['title'] = $element['#bundle'] == 'image' ? t('View larger image') : t('Watch video');

  // Add the image as a link to the detailed view
  $variables['media_gallery_item'] = theme('media_gallery_item', $link_vars);

  // Set the variables to theme the metadata.
  $meta_vars = array();
  $meta_vars['location'] = $element['#media_gallery_entity']->media_gallery_image_info_where[LANGUAGE_NONE][0]['value'];
  $meta_vars['title'] = isset($element['media_title']) ? $element['media_title'][0]['#markup'] : '';
  $meta_vars['link_path'] = $link_vars['link_path'];

  // Theme the metadata.
  $variables['media_gallery_meta'] = theme('media_gallery_meta', $meta_vars);
}