diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 1b9b8f8..ed5a3c8 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -8,6 +8,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Url; use Drupal\Component\Utility\String; use Symfony\Component\HttpFoundation\Request; @@ -172,30 +173,25 @@ function forum_entity_type_build(array &$entity_types) { } /** - * Implements hook_entity_bundle_info_alter(). + * Implements hook_term_url_info_alter() + * + * If the term is from a forum vocabulary, change the route name to forum.page */ -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'; +function forum_term_url_info_alter(&$uri, $term, $rel) { + if ($rel == 'canonical') { + $vid = \Drupal::config('forum.settings')->get('vocabulary'); + $bundle = $term->bundle(); + if ($vid == $bundle) { + $uri = new Url( + 'forum.page', + $uri->getRouteParameters(), + $uri->getOptions() + ); } } } /** - * 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/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 435cbe6..cf42c71 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -7,13 +7,17 @@ namespace Drupal\taxonomy\Entity; +use Drupal\Component\Utility\String; use Drupal\Core\Entity\ContentEntityBase; +use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\Url; use Drupal\taxonomy\TermInterface; /** @@ -34,7 +38,6 @@ * "translation" = "Drupal\taxonomy\TermTranslationHandler" * }, * base_table = "taxonomy_term_data", - * uri_callback = "taxonomy_term_uri", * fieldable = TRUE, * translatable = TRUE, * entity_keys = { @@ -58,6 +61,16 @@ class Term extends ContentEntityBase implements TermInterface { /** * {@inheritdoc} */ + public function urlInfo($rel = 'canonical') { + $uri = parent::urlInfo($rel); + // provide the chance for other modules to alter Term uri + \Drupal::moduleHandler()->alter('term_url_info', $uri, $this, $rel); + return $uri; + } + + /** + * {@inheritdoc} + */ public static function postDelete(EntityStorageInterface $storage, array $entities) { parent::postDelete($storage, $entities); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index fde291e..c337529 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -116,15 +116,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,