diff --git a/core/modules/taxonomy/config/views.view.taxonomy_term.yml b/core/modules/taxonomy/config/views.view.taxonomy_term.yml index fb45497..41ab04a 100644 --- a/core/modules/taxonomy/config/views.view.taxonomy_term.yml +++ b/core/modules/taxonomy/config/views.view.taxonomy_term.yml @@ -2,7 +2,7 @@ base_field: nid base_table: node core: '8' description: 'Customize the default taxonomy/term display.' -status: '0' +status: '1' display: default: id: default diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php index eb57cc5..968ea10 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php @@ -18,6 +18,19 @@ class TaxonomyController extends ControllerBase { /** + * Title callback for term pages. + * + * @param \Drupal\taxonomy\TermInterface $term + * A taxonomy term entity. + * + * @return + * The term name to be used as the page title. + */ + public function getTitle(TermInterface $term) { + return $term->label(); + } + + /** * Returns a rendered edit form to create a new term associated to the given vocabulary. * * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary @@ -35,19 +48,68 @@ public function addForm(VocabularyInterface $taxonomy_vocabulary) { } /** - * @todo Remove taxonomy_term_page(). + * Menu callback; displays all nodes associated with a term. + * + * @param \Drupal\taxonomy\TermInterface $term + * The taxonomy term entity. + * + * @return + * A structured array to be rendered by drupal_render(). */ - public function termPage(TermInterface $taxonomy_term) { - module_load_include('pages.inc', 'taxonomy'); - return taxonomy_term_page($taxonomy_term); + public function termPage(TermInterface $term) { + // Assign the term name as the page title. + drupal_set_title($term->label()); + + $build['#attached']['drupal_add_feed'][] = array('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, \Drupal::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' => '

', + '#markup' => t('There is currently no content classified with this term.'), + '#suffix' => '

', + ); + } + return $build; } /** - * @todo Remove taxonomy_term_feed(). + * Generate the content feed for a taxonomy term. + * + * @param \Drupal\taxonomy\TermInterface $term + * The taxonomy term entity. + * + * @return \Symfony\Component\HttpFoundation\Response + * A response object. */ - public function termFeed(TermInterface $taxonomy_term) { - module_load_include('pages.inc', 'taxonomy'); - return taxonomy_term_feed($taxonomy_term); + public function termFeed(TermInterface $term) { + $channel['link'] = url('taxonomy/term/' . $term->id(), array('absolute' => TRUE)); + $channel['title'] = \Drupal::config('system.site')->get('name') . ' - ' . $term->label(); + // Only display the description if we have a single term, to avoid clutter and confusion. + // HTML will be removed from feed description. + $channel['description'] = check_markup($term->description->value, $term->format->value, '', TRUE); + $nids = taxonomy_select_nodes($term->id(), FALSE, \Drupal::config('system.rss')->get('items.limit')); + + return node_feed($nids, $channel); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index 976fc4d..ccabab1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -207,7 +207,7 @@ function testTaxonomyIndex() { * Tests that there is a link to the parent term on the child term page. */ function testTaxonomyTermHierarchyBreadcrumbs() { - module_enable(array('views')); + \Drupal::moduleHandler()->install(array('views')); // Create two taxonomy terms and set term2 as the parent of term1. $term1 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index c385a3a..922f604 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -289,7 +289,7 @@ function testTermAutocompletion() { * Save, edit and delete a term using the user interface. */ function testTermInterface() { - module_enable(array('views')); + \Drupal::moduleHandler()->install(array('views')); $edit = array( 'name' => $this->randomName(12), 'description[value]' => $this->randomName(100), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php index 9b4611d..34a805a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php @@ -52,7 +52,7 @@ function testVocabularyPermissionsTaxonomyTerm() { // Edit the term. $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); $this->assertResponse(200); - $this->assertText($edit['name'], 'Edit taxonomy term form opened successfully.'); + $this->assertRaw($edit['name'], 'Edit taxonomy term form opened successfully.'); $edit['name'] = $this->randomName(); $this->drupalPostForm(NULL, $edit, t('Save')); @@ -80,7 +80,7 @@ function testVocabularyPermissionsTaxonomyTerm() { // Edit the term. $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); $this->assertResponse(200); - $this->assertText($term->name->value, 'Edit taxonomy term form opened successfully.'); + $this->assertRaw($term->name->value, 'Edit taxonomy term form opened successfully.'); $edit['name'] = $this->randomName(); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 2c7672b..1d3b6b9 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -249,6 +249,16 @@ function taxonomy_menu() { 'type' => MENU_SIBLING_LOCAL_TASK, ); + $items['taxonomy/term/%taxonomy_term'] = array( + 'title' => 'Taxonomy term', + 'route_name' => 'taxonomy.term_page', + ); + $items['taxonomy/term/%taxonomy_term/feed'] = array( + 'title' => 'Taxonomy term', + 'route_name' => 'taxonomy.term_feed', + 'type' => MENU_CALLBACK, + ); + $items['admin/structure/taxonomy/manage/%taxonomy_vocabulary'] = array( 'route_name' => 'taxonomy.overview_terms', 'title callback' => 'entity_page_label', diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 2733f54..9ca17af 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -75,3 +75,17 @@ taxonomy.overview_terms: _form: 'Drupal\taxonomy\Form\OverviewTerms' requirements: _entity_access: 'taxonomy_vocabulary.view' + +taxonomy.term_page: + path: '/taxonomy/term/{taxonomy_term}' + defaults: + _content: '\Drupal\taxonomy\Controller\TaxonomyController::termPage' + requirements: + _entity_access: 'taxonomy_term.view' + +taxonomy.term_feed: + path: '/taxonomy/term/{taxonomy_term}/feed' + defaults: + _content: '\Drupal\taxonomy\Controller\TaxonomyController::termFeed' + requirements: + _entity_access: 'taxonomy_term.view'