You are here

function media_gallery_list_galleries in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.pages.inc \media_gallery_list_galleries()

Page callback to list all galleries.

TODO: When I grow up I want to be a View.

1 string reference to 'media_gallery_list_galleries'
media_gallery_menu_alter in ./media_gallery.module
Implements hook_menu_alter().

File

./media_gallery.pages.inc, line 13
Common pages for the Media Gallery module.

Code

function media_gallery_list_galleries($term) {
  $collections_vid = variable_get('media_gallery_collection_vid', 0);
  if ($term->vid !== $collections_vid) {
    module_load_include('inc', 'taxonomy', 'taxonomy.pages');
    return taxonomy_term_page($term);
  }

  // Add front-end resources for drag-and-drop sorting.
  if (user_access('administer media galleries')) {
    drupal_add_library('system', 'ui.sortable');
    drupal_add_library('system', 'jquery.bbq');
    drupal_add_js(drupal_get_path('module', 'media_gallery') . '/media_gallery.dragdrop.js');
    drupal_add_css(drupal_get_path('module', 'media_gallery') . '/media_gallery.dragdrop.css');
    $sort_collection_url = url('media-gallery/sort/collection/' . $term->tid . '/' . drupal_get_token('media_gallery'));
    drupal_add_js(array(
      'mediaGallerySortCollectionUrl' => $sort_collection_url,
    ), array(
      'type' => 'setting',
    ));
  }

  // Assign the term name as the page title.
  drupal_set_title($term->name);

  // Build breadcrumb based on the hierarchy of the term.
  $current = (object) array(
    'tid' => $term->tid,
  );
  $breadcrumb = array();
  while ($parents = taxonomy_get_parents($current->tid)) {
    $current = array_shift($parents);
    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
  }
  $breadcrumb[] = l(t('Home'), NULL);
  $breadcrumb = array_reverse($breadcrumb);
  drupal_set_breadcrumb($breadcrumb);
  drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
  $build['term_heading'] = array(
    '#prefix' => '<div class="term-listing-heading">',
    '#suffix' => '</div>',
    'term' => taxonomy_term_view($term, 'full'),
  );

  // There is a small bug here with the "entity"
  $term_entity = new FieldsRSIPreventor($term);
  $limit = $term_entity
    ->getValue('media_gallery_columns') * $term_entity
    ->getValue('media_gallery_rows');
  if (!$limit) {
    $limit = 10;
  }
  $nids = media_gallery_select_galleries($term->tid, TRUE, $limit);
  if (!empty($nids)) {
    $nodes = node_load_multiple($nids);

    // Add the nodes to the build array, with a weight of 5.
    $build += node_view_multiple($nodes, 'teaser', 5);
    $build['pager'] = array(
      '#theme' => 'pager',
      '#weight' => 10,
    );
    $build['#term'] = $term;
    $build['#theme'] = 'media_gallery_collection';
  }
  else {
    $build['no_content'] = array(
      '#prefix' => '<p>',
      '#markup' => t('No galleries have been set up yet.'),
      '#suffix' => '</p>',
    );
    if (node_access('create', 'media-gallery')) {
      $build['no_content']['#markup'] .= ' ' . t('<a href="@link">Add a gallery.</a>', array(
        '@link' => url('node/add/media-gallery'),
      ));
    }
  }
  return $build;
}