Commit 7208952f authored by David_Rothstein's avatar David_Rothstein

Issue #1067120 followup by David_Rothstein, Berdir: Fix backwards...

Issue #1067120 followup by David_Rothstein, Berdir: Fix backwards compatibility issues for Drupal 7 on the taxonomy term page, and small documentation fixes.
parent 788c2ada
......@@ -184,9 +184,9 @@ function hook_taxonomy_term_delete($term) {
/**
* Act on a taxonomy term that is being assembled before rendering.
*
* The module may add elements to $term->content prior to rendering. This hook
* will be called after hook_view(). The structure of $term->content is a
* renderable array as expected by drupal_render().
* The module may add elements to $term->content prior to rendering. The
* structure of $term->content is a renderable array as expected by
* drupal_render().
*
* @param $term
* The term that is being assembled for rendering.
......
......@@ -762,7 +762,7 @@ function taxonomy_term_show($term) {
* @param $view_mode
* View mode, e.g. 'full', 'teaser'...
* @param $weight
* An integer representing the weight of the first node in the list.
* An integer representing the weight of the first taxonomy term in the list.
* @param $langcode
* (optional) A language code to use for rendering. Defaults to the global
* content language of the current request.
......@@ -819,7 +819,7 @@ function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NUL
);
drupal_alter('entity_view_mode', $view_mode, $context);
// Try to add in the core taxonomy pieces like description and nodes.
// Add the term description if the term has one and it is visible.
$type = 'taxonomy_term';
$entity_ids = entity_extract_ids($type, $term);
$settings = field_view_mode_settings($type, $entity_ids[2]);
......@@ -869,7 +869,7 @@ function taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL) {
$langcode = $GLOBALS['language_content']->language;
}
// Populate $node->content with a render() array.
// Populate $term->content with a render() array.
taxonomy_term_build_content($term, $view_mode, $langcode);
$build = $term->content;
......
......@@ -14,7 +14,9 @@
* The page content.
*/
function taxonomy_term_page($term) {
// Assign the term name as the page title.
// 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 term title.
drupal_set_title($term->name);
// Build breadcrumb based on the hierarchy of the term.
......@@ -33,17 +35,23 @@ function taxonomy_term_page($term) {
drupal_set_breadcrumb($breadcrumb);
drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $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.
$uri = entity_uri('taxonomy_term', $term);
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);
$build = taxonomy_term_show($term);
// Normally we would call taxonomy_term_show() here, but for backwards
// compatibility in Drupal 7 we do not want to do that (it produces different
// data structures and HTML markup than what Drupal 7 released with). Calling
// taxonomy_term_view() directly provides essentially the same thing, but
// allows us to wrap the rendered term in our desired array structure.
$build['term_heading'] = array(
'#prefix' => '<div class="term-listing-heading">',
'#suffix' => '</div>',
'term' => taxonomy_term_view($term, 'full'),
);
if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
$nodes = node_load_multiple($nids);
$build += node_view_multiple($nodes);
......
......@@ -1428,8 +1428,8 @@ class TaxonomyHooksTestCase extends TaxonomyWebTestCase {
// hook_entity_view() are invoked.
$term = taxonomy_term_load($term->tid);
$term_build = taxonomy_term_page($term);
$this->assertFalse(empty($term_build['taxonomy_terms'][$term->tid]['taxonomy_test_term_view_check']), 'hook_taxonomy_term_view() was invoked when viewing the term.');
$this->assertFalse(empty($term_build['taxonomy_terms'][$term->tid]['taxonomy_test_entity_view_check']), 'hook_entity_view() was invoked when viewing the term.');
$this->assertFalse(empty($term_build['term_heading']['term']['taxonomy_test_term_view_check']), 'hook_taxonomy_term_view() was invoked when viewing the term.');
$this->assertFalse(empty($term_build['term_heading']['term']['taxonomy_test_entity_view_check']), 'hook_entity_view() was invoked when viewing the term.');
// Delete the term.
taxonomy_term_delete($term->tid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment