forum module uses hook_link_alter instead of taxonomy_term_path hook

vito_swat - December 5, 2007 - 00:02
Project:Drupal
Version:5.x-dev
Component:forum.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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:

<?php
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:

<?php
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.

AttachmentSizeStatusTest resultOperations
forum.patch1.11 KBIgnoredNoneNone

#1

greggles - December 16, 2007 - 19:52
Version:5.3» 6.x-dev

This 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.

#2

Liam McDermott - February 11, 2008 - 13:16
Version:6.x-dev» 7.x-dev
Status:needs review» needs work

This will need to be re-rolled against HEAD.

#3

alpritt - May 14, 2008 - 11:29
Status:needs work» needs review

Re-rolled for HEAD and added comment.

AttachmentSizeStatusTest resultOperations
forum_hook_term_path.patch1.11 KBIgnoredNoneNone

#4

Gurpartap Singh - May 19, 2008 - 06:54

Drupal coding standards have changed for the placement of concatenation dot.

This looks quick and good. Dries?

AttachmentSizeStatusTest resultOperations
forum_hook_term_path.patch1.11 KBIgnoredNoneNone

#5

Murz - May 20, 2008 - 09:27

On 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

<?php
  $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.

#6

catch - May 20, 2008 - 10:03
Status:needs review» reviewed & tested by the community

Tested this on 5.x without issue, works nice. Good find.

#7

catch - July 22, 2008 - 11:11

Still applies cleanly.

#8

Dries - August 11, 2008 - 21:57
Status:reviewed & tested by the community» fixed

This does not seem to break any forum tests. Committed to CVS HEAD. Thanks.

#9

Anonymous (not verified) - August 25, 2008 - 22:04
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#10

vito_swat - September 29, 2008 - 23:19
Version:7.x-dev» 6.x-dev
Status:closed» reviewed & tested by the community

Any reason for not committing this to 6.x and 5.x?

#11

spatz4000 - September 30, 2008 - 15:53
Status:reviewed & tested by the community» active

#12

Dave Reid - February 28, 2009 - 20:40
Status:active» reviewed & tested by the community

Straight upport to D6.

AttachmentSizeStatusTest resultOperations
197864-forum-term-path-D6.patch1.12 KBIgnoredNoneNone

#13

Gábor Hojtsy - March 30, 2009 - 11:10
Version:6.x-dev» 5.x-dev
Status:reviewed & tested by the community» patch (to be ported)

How this is invoked was not mentioned here, neither on the hook page, so I've looked that up:

<?php
/**
* For vocabularies not maintained by taxonomy.module, give the maintaining
* module a chance to provide a path for terms in that vocabulary.
*
* @param $term
*   A term object.
* @return
*   An internal Drupal path.
*/

function taxonomy_term_path($term) {
 
$vocabulary = taxonomy_vocabulary_load($term->vid);
  if (
$vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term))
{
    return
$path;
  }
  return
'taxonomy/term/'. $term->tid;
}
?>

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."

#14

vito_swat - April 27, 2009 - 15:14
Status:patch (to be ported)» reviewed & tested by the community

backport for 5.x is an attachment to the issue post (#0). tested in #5 and #6 and by me.

#15

drumm - April 29, 2009 - 18:54
Status:reviewed & tested by the community» fixed

Committed to 5.x.

#16

System Message - May 13, 2009 - 19:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.