The current version (1.284) of taxonomy.module has had taxonomy_term_path removed at some point, apparently when hook_link_alter was introduced, as mentioned in the 4.8 conversion guide.
The immediate workaround for affected modules is simple (in contrib, taxonomy_context and categories are affected, custom local modules and themes are probably more significant): just replace
$path = taxonomy_term_path($term);
by
$path = "taxonomy/term/$term->tid";
However, in the long run, I think it is better (more future-proof) to have taxonomy generate its links than to rely on an undocumented (is it really ?) hard-coded path. That way, in case some radical URL scheme change is required, all it takes is one change in taxonomy.module, not changes in every dependent module.
The constant string is currently used in core by:
forum.module: it used to be the only function in core relying ontaxonomy_term_path, if I'm not mistaken (http://drupal.org/node/18260#comment-96789)legacy.modulepath.module: uses it only in its help strings for users- and of course
taxonomy.moduleitself
However, the reimplementation of the function in taxonomy.module should probably not use the older method that didn't allow for hook_link_alter to work.
Last but not least, if it is decided to keep the function removed, that removal should be documented in the 4.8 conversion guide.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | taxonomy_get_path.patch | 3.03 KB | robertdouglass |
| #9 | taxonomy_get_path_0.txt | 1.46 KB | robertdouglass |
| #6 | taxonomy_get_path.txt | 1.46 KB | robertdouglass |
Comments
Comment #1
chx commentedwith hook_link_alter and preg you could replace the taxonomy path
probably that can could be the reason for the removal.
Comment #2
chx commentedbut still, the change should be documented, with appropriate code examples (do not look at me, I am currently cooking the pre CCK patch)
Comment #3
fgmAs we discussed the whole point is for modules to obtain a taxonomy path as it should be by default. It can be altered by a module using
hook_link_alterif applicable, or left unchanged to has a resilient link system.Comment #4
robertdouglass commentedisn't there a difference between a path and a link? Anyway, unaware as I was of the history of the issue, I wrote myself a helper function for generating taxonomy paths.
I'm setting this to patch (code needs review) even though this obviously isn't a patch because you can read it as is and use copy and paste if it is deemed worthy of taxonomy module. I'll provide a patch to Drupal to make use of it if people like the function.
Comment #5
robertdouglass commentedSlight aesthetic improvements; 'page' is never explicitely stated and depth is omitted when zero.
Comment #6
robertdouglass commentedmissing semicolon in that last version.
Comment #7
dries commentedI don't think the current system is broken. Robert's function is interesting and might pave the path for a views API.
Can this function be re-used internally? Let the taxonomy module eat its own dog food?
Ideally, we'd also have a function that does the inverse. Given a path, it builds a query.
Comment #8
robertdouglass commentedNice suggetions, Dries. I'm on vacation now, will address these issues when I return. I think the "eat its own dogfood" part belongs with this patch, whereas the inverse bit should be separate. Agree?
Comment #9
robertdouglass commentedtaxonomy_term_path had been reintroduced, but now I've replaced it with my proposed function. Taxonomy_term_path only got called once in all of Drupal core. I've integrated its functionality into my function and removed it. Now taxonomy_get_path is called where taxonomy_term_path used to. There is a slight overhead increase (an extra if statement), but otherwise no difference for the previously existing cases. Now, however, the full power of our taxonomy REST API is exposed.
Comment #10
robertdouglass commentedwrong file.
Comment #11
robertdouglass commentedComment #12
fgmRobert,
There is also the case of the places where the hardcoded string is (was) used, which I mentioned in the initial description of the problem. Maybe it would make sense to patch them too ?
Comment #13
robertdouglass commentedyou mean these?
# forum.module : it used to be the only function in core relying on taxonomy_term_path, if I'm not mistaken (http://drupal.org/node/18260#comment-96789)
# legacy.module
# path.module : uses it only in its help strings for users
Yes, that would be necessary as well. I'll wait for committer feedback before doing that, though.
Comment #14
robertdouglass commented@fgm in the meantime, the function needs some rigorous testing, if you feel up to it.
Comment #15
fgmThe code looks great to me. However:
Comment #16
robertdouglass commentedIt's there, but just for the exact case of one single term object:
I suppose it is in the wrong place. I included it there as a hack to guarantee backwards compatability, but it should really be applied even-handedly. It's just that it would change the API for hook_term_path altogether and make it hook_terms_path instead, and all modules would then have to ready themselves for all the cases that this function handles. I'd be fine with that and would assist in the transition. Dries?
Comment #17
robertdouglass commentedchanging the title to reflect the current nature of the patch
Comment #18
Bèr Kessels commentedFWIW, i added this in helpers module. In a new file/module called helpers_taxonomy.module.
Comment #19
webchickpatching file modules/taxonomy/taxonomy.module
Hunk #1 succeeded at 47 with fuzz 1 (offset 16 lines).
Hunk #2 FAILED at 63.
Hunk #3 succeeded at 893 (offset 105 lines).
1 out of 3 hunks FAILED -- saving rejects to file modules/taxonomy/taxonomy.module.rej
Comment #20
webchickComment #21
nancydruI assume this will not be in D6.
Comment #22
panchoI guess not, since this is a major API change. Would be great though early in D7.
Comment #23
xanoSubscribing.
Comment #24
catchComment #25
dave reidWould it possibly be easier to replace this whole logic with #320331: Turn custom_url_rewrite_inbound and custom_url_rewrite_outbound into hooks? We could replace form_term_path with forum_url_rewrite_outbound and forum_url_rewrite_inbound(). Other modules would do the same.
Comment #26
nancydruWith all the many, many places I use taxonomy_term_path, I'm not sure I like that idea.
Comment #27
dave reidI think you misunderstand. Usually you call taxonomy_term_path inside of url() or l(). If this were converted to hook_url_alters then it would be called automatically by url() and you would just simply remove the taxonomy_term_path() call.
Comment #28
nancydruWell, I'm all for making life easier. Thanks for educating an old girl.
Comment #29
dropcube commentedFor taxonomy links and modules taxonomy_term_path() and hook_term_path() have been replaced by hook_url_alter_outbound().
http://drupal.org/node/224333#hook_url_outbound_alter
Issue: #320331: Turn custom_url_rewrite_inbound and custom_url_rewrite_outbound into hooks