Since you still need to generate path aliases for nodes, I would rather use the Pathauto module. The code you show has the following problems:
- It doesn't work for Drupal 7, since hook_term_path() is not used from Drupal 7
It works only when the module handling the vocabulary is not the Taxonomy module, since the hook is invoked from the following function.
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;
}
There should not be the need of calling taxonomy_get_term()
since the taxonomy term object is already passed to the hook.
A Drupal 7 solution would be implementing hook_url_inbound_alter() and hook_url_outbound_alter(), for which the equivalent in Drupal 6 are two functions to add to the settings.php file: custom_url_rewrite_inbound() and custom_url_rewrite_outbound().
As for when that hooks/functions should be used instead of using path aliases with the Pathauto module, you can look at What is the difference between implementing hook_url_inbound_alter() and hook_url_outbound_alter(), and using a path alias?
Using hook_url_outbound_alter()
has some potential performance issues because it is executed by every single URL on a page via the url() function. This means a module could implement hook_url_outbound_alter()
with some complex and slow code that is called 100's of times per page.
Also hook_url_outbound_alter() allows a link's $options
, including its query string, to be altered, which is impossible to do to path aliases and a very useful feature. For example, I have altered internal RSS URLs to point to their respective Feedburner and iTunes URLs.
Conceptually, the Path module should be calling the hook_url_*_alter()
hooks but it is probably slightly faster to have the drupal_get_path_alias()
calls directly in url()
.