From ba96cffdb7d3f76254ff7391523a6fc34abf10e2 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 6 Apr 2010 19:49:03 +0000 Subject: - Patch #699440 by scor, effulgentsia, noahb, catch: add bundle support to entity_uri() callback to remove performance overhead of forum_url_outbound_alter(). --- modules/forum/forum.module | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'modules/forum') diff --git a/modules/forum/forum.module b/modules/forum/forum.module index ae8f5fb31..4811750fd 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -218,6 +218,36 @@ function forum_init() { drupal_add_css(drupal_get_path('module', 'forum') . '/forum.css'); } +/** + * Implements hook_entity_info_alter(). + */ +function forum_entity_info_alter(&$info) { + // Take over URI constuction for taxonomy terms that are forums. + if ($vid = variable_get('forum_nav_vocabulary', 0)) { + // Within hook_entity_info(), we can't invoke entity_load() as that would + // cause infinite recursion, so we call taxonomy_vocabulary_get_names() + // instead of taxonomy_vocabulary_load(). All we need is the machine name + // of $vid, so retrieving and iterating all the vocabulary names is somewhat + // inefficient, but entity info is cached across page requests, and an + // iteration of all vocabularies once per cache clearing isn't a big deal, + // and is done as part of taxonomy_entity_info() anyway. + foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) { + if ($vid == $vocabulary->vid) { + $info['taxonomy_term']['bundles'][$machine_name]['uri callback'] = 'forum_uri'; + } + } + } +} + +/** + * Entity URI callback. + */ +function forum_uri($forum) { + return array( + 'path' => 'forum/' . $forum->tid, + ); +} + /** * Check whether a content type can be used in a forum. * @@ -681,18 +711,6 @@ function forum_form($node, $form_state) { return $form; } -/** - * Implements hook_url_outbound_alter(). - */ -function forum_url_outbound_alter(&$path, &$options, $original_path) { - if (preg_match('!^taxonomy/term/(\d+)!', $path, $matches)) { - $term = taxonomy_term_load($matches[1]); - if ($term && $term->vocabulary_machine_name == 'forums') { - $path = 'forum/' . $matches[1]; - } - } -} - /** * Returns a list of all forums for a given taxonomy id * -- cgit v1.2.3