You are here

function theme_media_gallery_teaser in Media Gallery 7.2

Same name and namespace in other branches
  1. 7 media_gallery.theme.inc \theme_media_gallery_teaser()

Displays a gallery node as a teaser.

The Galleries page displays a grid of gallery teasers. Each gallery teaser is themed as a node using node.tpl.php or one if its overrides. Where that template file calls

render($content);

, the output of this function is returned.

File

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

Code

function theme_media_gallery_teaser($variables) {
  $element = $variables['element'];
  $node = $element['#node'];
  if (isset($element['media_gallery_file'][0])) {
    $element['media_gallery_file'][0]['#theme'] = 'media_gallery_file_field_inline';
    $image = drupal_render($element['media_gallery_file'][0]);
  }
  else {
    $image = theme('image', array(
      'path' => drupal_get_path('module', 'media_gallery') . '/images/empty_gallery.png',
    ));
  }
  $link_vars = array();
  $link_vars['image'] = $image;
  $uri = entity_uri('node', $node);
  $link_vars['link_path'] = $uri['path'];
  $link_vars['classes'] = array(
    'media-gallery-thumb',
  );
  $output = '<div class="media-collection-item-wrapper"><img class="stack-image" src="' . base_path() . drupal_get_path('module', 'media_gallery') . '/images/stack_bg.png" />' . theme('media_gallery_item', $link_vars) . '</div>';

  // Set the variables to theme the meta data if there is a term on the node
  if (isset($node->term)) {
    $term = $node->term;
    $meta_vars = array();
    $meta_vars['location'] = $term->media_gallery_image_info_where[LANGUAGE_NONE][0]['value'];
    $meta_vars['title'] = $node->title;
    $meta_vars['link_path'] = $link_vars['link_path'];

    // Organize the file count by type. We only expect images and videos for
    // now, so we put those first and group the others together into a general
    // category at the end.
    $type_count = media_gallery_get_media_type_count($node, 'media_gallery_file_original');
    $description = array();
    if (isset($type_count['image'])) {
      $count = $type_count['image'];
      $description[] = format_plural($count, '<span>@num image</span>', '<span>@num images</span>', array(
        '@num' => $count,
      ));
      unset($type_count['image']);
    }
    if (isset($type_count['video'])) {
      $count = $type_count['video'];
      $description[] = format_plural($count, '<span>@num video</span>', '<span>@num videos</span>', array(
        '@num' => $count,
      ));
      unset($type_count['video']);
    }
    if (!empty($type_count)) {
      $count = array_sum($type_count);
      $description[] = format_plural($count, '<span>@num other item</span>', '<span>@num other items</span>', array(
        '@num' => $count,
      ));
    }
    $meta_vars['description'] = implode(', ', $description);

    // Add the meta information
    $output .= theme('media_gallery_meta', $meta_vars);
  }
  return $output;
}