diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 8d4a9f4..b54de4f 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -115,19 +115,10 @@ 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(). + * Entity URI callback. + * + * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.0. + * Use $forum->url() instead. */ function forum_uri($forum) { return Url::fromRoute('forum.page', ['taxonomy_term' => $forum->id()]); @@ -546,7 +537,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 = array('#markup' => $forum->description->value); - $variables['forums'][$id]->link = forum_uri($forum); + $variables['forums'][$id]->link = $forum->url(); $variables['forums'][$id]->name = $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 5f56f3d..092f9eb 100644 --- a/core/modules/forum/forum.services.yml +++ b/core/modules/forum/forum.services.yml @@ -19,7 +19,11 @@ 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'] forum.uninstall_validator: class: Drupal\forum\ForumUninstallValidator tags: diff --git a/core/modules/forum/src/Access/RouteProcessor.php b/core/modules/forum/src/Access/RouteProcessor.php new file mode 100644 index 0000000..599d76f --- /dev/null +++ b/core/modules/forum/src/Access/RouteProcessor.php @@ -0,0 +1,62 @@ +configFactory = $config_factory; + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) { + if ($route_name == 'entity.taxonomy_term.canonical' && !empty($parameters['taxonomy_term'])) { + // Take over URI construction for taxonomy terms that belong to forum. + if ($vid = $this->configFactory->get('forum.settings')->get('vocabulary')) { + if ($this->entityTypeManager->getStorage('taxonomy_term')->load($parameters['taxonomy_term'])->getVocabularyId() == $vid) { + $route->setPath('/forum/{taxonomy_term}'); + } + } + } + } + +}