function page_manager_term_view_page

Entry point for our overridden term view.

This function asks its assigned handlers who, if anyone, would like to run with it. If no one does, it passes through to Drupal core's term view, which is term_page_view().

1 string reference to 'page_manager_term_view_page'
page_manager_term_view_menu_alter in page_manager/plugins/tasks/term_view.inc
Callback defined by page_manager_term_view_page_manager_tasks().

File

page_manager/plugins/tasks/term_view.inc, line 109

Code

function page_manager_term_view_page($term, $depth = NULL) {
    // Prep the term to be displayed so all of the regular hooks are triggered.
    // Rather than calling taxonomy_term_page() directly, as it that would
    // potentially load nodes that were not necessary, execute some of the code
    // prior to identifying the correct CTools or Page Manager task handler and
    // only proceed with the rest of the code if necessary.
    // Assign the term name as the page title.
    drupal_set_title($term->name);
    // If there is a menu link to this term, the link becomes the last part
    // of the active trail, and the link name becomes the page title.
    // Thus, we must explicitly set the page title to be the node title.
    $uri = entity_uri('taxonomy_term', $term);
    // Set the term path as the canonical URL to prevent duplicate content.
    drupal_add_html_head_link(array(
        'rel' => 'canonical',
        'href' => url($uri['path'], $uri['options']),
    ), TRUE);
    // Set the non-aliased 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);
    // Trigger the main.
    $build = taxonomy_term_show($term);
    // Load my task plugin.
    $task = page_manager_get_task('term_view');
    // Load the term into a context.
    ctools_include('context');
    ctools_include('context-task-handler');
    $contexts = ctools_context_handler_get_task_contexts($task, '', array(
        $term,
        $depth,
    ));
    if (empty($contexts)) {
        return MENU_NOT_FOUND;
    }
    // Build the full output using the configured CTools plugin.
    $output = ctools_context_handler_render($task, '', $contexts, array(
        $term->tid,
    ));
    if ($output !== FALSE) {
        return $output;
    }
    // Try loading an override plugin.
    foreach (module_implements('page_manager_override') as $module) {
        $call = $module . '_page_manager_override';
        if (($rc = $call('term_view')) && function_exists($rc)) {
            return $rc($term, $depth);
        }
    }
    // Otherwise, fall back to replicating the output normally generated by
    // taxonomy_term_page().
    // Build breadcrumb based on the hierarchy of the term.
    $current = (object) array(
        'tid' => $term->tid,
    );
    // @todo This overrides any other possible breadcrumb and is a pure hard-coded
    //   presumption. Make this behavior configurable per vocabulary or term.
    $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);
    if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
        $nodes = node_load_multiple($nids);
        $build += 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;
}