diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-04-06 19:49:03 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-04-06 19:49:03 +0000 |
commit | ba96cffdb7d3f76254ff7391523a6fc34abf10e2 (patch) | |
tree | dd42dc052efda70657a1e73ab1e47964c920d734 /modules/forum | |
parent | c2b1029595afe103b5f1533604cfe658755f1f8d (diff) | |
download | brdo-ba96cffdb7d3f76254ff7391523a6fc34abf10e2.tar.gz brdo-ba96cffdb7d3f76254ff7391523a6fc34abf10e2.tar.bz2 |
- Patch #699440 by scor, effulgentsia, noahb, catch: add bundle support to entity_uri() callback to remove performance overhead of forum_url_outbound_alter().
Diffstat (limited to 'modules/forum')
-rw-r--r-- | modules/forum/forum.module | 42 |
1 files changed, 30 insertions, 12 deletions
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 @@ -219,6 +219,36 @@ function forum_init() { } /** + * 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. * * @param $node @@ -682,18 +712,6 @@ function forum_form($node, $form_state) { } /** - * 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 * * Forum objects contain the following fields |