function taxonomy_term_page

Menu callback; displays all nodes associated with a term.

Parameters

Drupal\taxonomy\Plugin\Core\Entity\Term $term: The taxonomy term entity.

1 string reference to 'taxonomy_term_page'
taxonomy_menu in drupal/core/modules/taxonomy/taxonomy.module
Implements hook_menu().

File

drupal/core/modules/taxonomy/taxonomy.pages.inc, line 18
Page callbacks for the taxonomy module.

Code

function taxonomy_term_page(Term $term) {

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

  // @todo This overrides any other possible breadcrumb and is a pure hard-coded
  //   presumption. Make this behavior configurable per vocabulary or term.
  $breadcrumb = array();
  $current = $term;
  while ($parents = taxonomy_term_load_parents($current
    ->id())) {
    $current = array_shift($parents);
    $breadcrumb[] = l($current
      ->label(), 'taxonomy/term/' . $current
      ->id());
  }
  $breadcrumb[] = l(t('Home'), NULL);
  $breadcrumb = array_reverse($breadcrumb);
  drupal_set_breadcrumb($breadcrumb);
  drupal_add_feed('taxonomy/term/' . $term
    ->id() . '/feed', 'RSS - ' . $term
    ->label());
  foreach ($term
    ->uriRelationships() as $rel) {
    $uri = $term
      ->uri($rel);

    // Set the term path as the canonical URL to prevent duplicate content.
    drupal_add_html_head_link(array(
      'rel' => $rel,
      'href' => url($uri['path'], $uri['options']),
    ), TRUE);
    if ($rel == 'canonical') {

      // Set the non-aliased canonical path as a default shortlink.
      drupal_add_html_head_link(array(
        'rel' => 'shortlink',
        'href' => url($uri['path'], array_merge($uri['options'], array(
          'alias' => TRUE,
        ))),
      ), TRUE);
    }
  }
  $build['taxonomy_terms'] = taxonomy_term_view_multiple(array(
    $term
      ->id() => $term,
  ));
  if ($nids = taxonomy_select_nodes($term
    ->id(), TRUE, config('node.settings')
    ->get('items_per_page'))) {
    $nodes = node_load_multiple($nids);
    $build['nodes'] = node_view_multiple($nodes);
    $build['pager'] = array(
      '#theme' => 'pager',
      '#weight' => 5,
    );
  }
  else {
    $build['no_content'] = array(
      '#prefix' => '<p>',
      '#markup' => t('There is currently no content classified with this term.'),
      '#suffix' => '</p>',
    );
  }
  return $build;
}