Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there any particular reason for forum module not to implement taxonomy_term_path hook?
instead of very complicated and time consuming (if for each link) code like current:
function forum_link_alter(&$node, &$links) {
foreach ($links as $module => $link) {
if (strstr($module, 'taxonomy_term')) {
// Link back to the forum and not the taxonomy term page. We'll only
// do this if the taxonomy term in question belongs to forums.
$tid = str_replace('taxonomy/term/', '', $link['href']);
$term = taxonomy_get_term($tid);
if ($term->vid == _forum_get_vid()) {
$links[$module]['href'] = str_replace('taxonomy/term', 'forum', $link['href']);
}
}
}
}
there could be only this:
function forum_term_path($term) {
return 'forum/'. $term->tid;
}
Changing those lines of code provides the same functionality with much less and faster code and gives chance to contributed modules to properly handle or imitate forum taxonomy links
This patch should be also rerolled versus D6.
Comment | File | Size | Author |
---|---|---|---|
#12 | 197864-forum-term-path-D6.patch | 1.12 KB | Dave Reid |
#4 | forum_hook_term_path.patch | 1.11 KB | Gurpartap Singh |
#3 | forum_hook_term_path.patch | 1.11 KB | alpritt |
forum.patch | 1.11 KB | vito_swat | |
Comments
Comment #1
gregglesThis makes sense to me. vito_swat - what do you think about tackling this in D6 first? I think Drumm prefers to have bugs fixed in HEAD and then backported.
Comment #2
Liam McDermott CreditAttribution: Liam McDermott commentedThis will need to be re-rolled against HEAD.
Comment #3
alpritt CreditAttribution: alpritt commentedRe-rolled for HEAD and added comment.
Comment #4
Gurpartap Singh CreditAttribution: Gurpartap Singh commentedDrupal coding standards have changed for the placement of concatenation dot.
This looks quick and good. Dries?
Comment #5
MurzOn my Drupal 5.7 works good and smalls query list by many queries!
And I have found a bug in
function forum_link_alter(&$node, &$links)
from 5.x versions:String
$tid = str_replace('taxonomy/term/', '', $link['href']);
does not replace 'taxonomy' always, because taxonomy link may be not only like 'taxonomy/term/%', but much more, for example - 'nodeorder/term/%'. In this case function forum_link_alter generates bad function call like this:term = taxonomy_get_term('nodeorder/term/6');
.I hope that in 7.x this bug will be solved, because in my 5.x and 6.x i needs to solve it with hands for perfomance reasons.
Comment #6
catchTested this on 5.x without issue, works nice. Good find.
Comment #7
catchStill applies cleanly.
Comment #8
Dries CreditAttribution: Dries commentedThis does not seem to break any forum tests. Committed to CVS HEAD. Thanks.
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #10
vito_swat CreditAttribution: vito_swat commentedAny reason for not committing this to 6.x and 5.x?
Comment #11
StevenPatzComment #12
Dave ReidStraight upport to D6.
Comment #13
Gábor HojtsyHow this is invoked was not mentioned here, neither on the hook page, so I've looked that up:
From this, and taxonomy module's use of taxonomy_term_path(), it looks like this is a very good change indeed. Thanks, committed.
This should also be backported to 5.x. (I did need to modify Dave's reroll above for spacing code style for Drupal 6). This was my commit message:
cvs commit -m "#197864 by vito_swat, alpritt, Murz, catch: Use hook_term_path() in forum module instead of hook_link_alter(); simplfies code, improves performance and compatibility."
Comment #14
vito_swat CreditAttribution: vito_swat commentedbackport for 5.x is an attachment to the issue post (#0). tested in #5 and #6 and by me.
Comment #15
drummCommitted to 5.x.