diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index d30c85b..d2f5230 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -170,30 +170,6 @@ function forum_entity_type_build(array &$entity_types) { } /** - * Implements hook_entity_bundle_info_alter(). - */ -function forum_entity_bundle_info_alter(&$bundles) { - // Take over URI construction for taxonomy terms that are forums. - if ($vid = \Drupal::config('forum.settings')->get('vocabulary')) { - if (isset($bundles['taxonomy_term'][$vid])) { - $bundles['taxonomy_term'][$vid]['uri_callback'] = 'forum_uri'; - } - } -} - -/** - * Entity URI callback used in forum_entity_bundle_info_alter(). - */ -function forum_uri($forum) { - return array( - 'route_name' => 'forum.page', - 'route_parameters' => array( - 'taxonomy_term' => $forum->id(), - ), - ); -} - -/** * Implements hook_node_validate(). * * Checks in particular that the node is assigned only a "leaf" term in the diff --git a/core/modules/forum/forum.services.yml b/core/modules/forum/forum.services.yml index d5c0fe3..566492b 100644 --- a/core/modules/forum/forum.services.yml +++ b/core/modules/forum/forum.services.yml @@ -19,3 +19,8 @@ services: arguments: ['@database', '@forum_manager'] tags: - { name: backend_overridable } + forum.route_processor: + class: Drupal\forum\Access\RouteProcessor + tags: + - { name: route_processor_outbound } + arguments: ['@config.factory'] diff --git a/core/modules/forum/src/Access/RouteProcessor.php b/core/modules/forum/src/Access/RouteProcessor.php new file mode 100644 index 0000000..475ac7f --- /dev/null +++ b/core/modules/forum/src/Access/RouteProcessor.php @@ -0,0 +1,52 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public function processOutbound(Route $route, array &$parameters) { + // @todo Check the route machine name here https://drupal.org/node/2283851 + if ($route->getPath() == '/taxonomy/term/{taxonomy_term}' && !empty($parameters['taxonomy_term'])) { + // Take over URI construction for taxonomy terms that are forums. + if ($vid = $this->configFactory->get('forum.settings')->get('vocabulary')) { + if (Term::load($parameters['taxonomy_term'])->getVocabularyId() == $vid) { + $route->setPath('/forum/{taxonomy_term}'); + } + } + } + } + +} diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index 2bdbd96..0cda59d 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -182,6 +182,11 @@ function testForum() { // Test adding a comment to a forum topic. $node = $this->createForumTopic($this->forum, FALSE); + + // Make sure the forum field points to the forum. + $elements = $this->xpath('//div[contains(@class, "field-name-taxonomy-forums")]//a[contains(@href, :href)]', array(':href' => 'forum/' . $this->forum['tid'])); + $this->assertEqual(count($elements), 1, 'Found taxonomy term overriden link.'); + $edit = array(); $edit['comment_body[0][value]'] = $this->randomMachineName(); $this->drupalPostForm('node/' . $node->id(), $edit, t('Save')); diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index d01759f..056bd54 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -32,7 +32,6 @@ * }, * base_table = "taxonomy_term_data", * data_table = "taxonomy_term_field_data", - * uri_callback = "taxonomy_term_uri", * fieldable = TRUE, * translatable = TRUE, * entity_keys = { diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 3058dc3..f282f4e 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -117,15 +117,6 @@ function taxonomy_permission() { } /** - * Entity URI callback. - */ -function taxonomy_term_uri($term) { - return new Url('taxonomy.term_page', array( - 'taxonomy_term' => $term->id(), - )); -} - -/** * Return nodes attached to a term across all field instances. * * This function requires taxonomy module to be maintaining its own tables,