diff --git a/modules/taxonomy/taxonomy.api.php b/modules/taxonomy/taxonomy.api.php index 10575c575b93859d4b0cb98481b1927b26cbe874..5667eb96d5d5ac05a3e26312b25822177e885969 100644 --- a/modules/taxonomy/taxonomy.api.php +++ b/modules/taxonomy/taxonomy.api.php @@ -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. diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 905923dbfc5cfbf5878005365c170cbcbd67329f..9be7dfcbe9e44375443761fad97d6c545a42b4da 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -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; diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc index 4d2c4e6fca1ebfe8fc667ab380f94898c86fd77a..299c7bb6ee1f158184b593b720e58e2b633cd7c6 100644 --- a/modules/taxonomy/taxonomy.pages.inc +++ b/modules/taxonomy/taxonomy.pages.inc @@ -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' => '
', + '#suffix' => '
', + '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); diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 4cfb81b28f5e96a6f4b2b56a08a6dc6ab6b37a28..123bdce40fed3b8f74a2d4afddd224f503429cdb 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -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);