diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 2cf0c53..88fc830 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -114,25 +114,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 Url::fromRoute('forum.page', ['taxonomy_term' => $forum->id()]); -} - -/** * Implements hook_entity_bundle_field_info_alter(). */ function forum_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) { @@ -540,7 +521,7 @@ function template_preprocess_forum_list(&$variables) { // Sanitize each forum so that the template can safely print the data. foreach ($variables['forums'] as $id => $forum) { $variables['forums'][$id]->description = Xss::filterAdmin($forum->description->value); - $variables['forums'][$id]->link = forum_uri($forum); + $variables['forums'][$id]->link = $forum->url(); $variables['forums'][$id]->name = String::checkPlain($forum->label()); $variables['forums'][$id]->is_container = !empty($forum->forum_container->value); $variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; diff --git a/core/modules/forum/forum.services.yml b/core/modules/forum/forum.services.yml index d5c0fe3..c405125 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', '@entity.manager'] diff --git a/core/modules/forum/src/Access/RouteProcessor.php b/core/modules/forum/src/Access/RouteProcessor.php new file mode 100644 index 0000000..a6f0bab --- /dev/null +++ b/core/modules/forum/src/Access/RouteProcessor.php @@ -0,0 +1,61 @@ +configFactory = $config_factory; + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public function processOutbound($route_name, Route $route, array &$parameters) { + if ($route_name == 'entity.taxonomy_term.canonical' && !empty($parameters['taxonomy_term'])) { + // Take over URI construction for taxonomy terms that belongs to forum. + if ($vid = $this->configFactory->get('forum.settings')->get('vocabulary')) { + if ($this->entityManager->getStorage('taxonomy_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 e75507a..15f3571 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -215,6 +215,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 7a1cc5f..24a225f 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -34,7 +34,6 @@ * }, * base_table = "taxonomy_term_data", * data_table = "taxonomy_term_field_data", - * uri_callback = "taxonomy_term_uri", * translatable = TRUE, * entity_keys = { * "id" = "tid", diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index c1896fd..ea62666 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -104,15 +104,6 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) { } /** - * Entity URI callback. - */ -function taxonomy_term_uri($term) { - return new Url('entity.taxonomy_term.canonical', array( - 'taxonomy_term' => $term->id(), - )); -} - -/** * Implements hook_page_attachments_alter(). */ function taxonomy_page_attachments_alter(array &$page) {