This post is as much to discuss this as it is a feature request. If it seems to have merit, I am certainly willing to work on a patch.

I have been approached about a possible module involving vocabularies. As I was reviewing possible APIs (hooks), I ran across the hook_taxonomy. This might have been useful in what I want to do. Unfortunately, it is a bit inconsistent with other core APIs in that it does not have a "load" call. I would think that there are a few modules (Taxonomy Image comes quickly to mind) which could be streamlined somewhat (eliminating duplicate queries, for example) by allowing additions to the vocabulary or term information at the time it is initially loaded rather than every time it is referenced (as in hook_links or hook_link_alter). This could generate even more performance gains if taxonomy uses caching (I see posts about that).

In the Taxonomy Image example, that module could use hook_taxonomy('load') to get the image associated with the term/vocabulary when that item is loaded rather than having user code issue queries to get the image every time it is used. This could potentially save a large number of queries.

Does this make sense? Is it worth pursuing?

I realize it may be too late for D6, so feel free to move it to D7 if it is.

Comments

nancydru’s picture

Version: 6.x-dev » 7.x-dev
dman’s picture

While it's logical to be consistent, I'm having trouble imagining too many more use-cases.
I like taxonomy_image, and yes, this does illustrate where it should fit...
... what else enhances taxonomy objects? I haven't seen a lot.

... not saying this is a bad idea, just genuinely interested in what similar functionality folk have tried to make...

MiMe’s picture

Well, I can say that we at our office has had to do coding in the theme template file and use the function theme_taxonomy_term_page to interact with taxonomies and terms. For example if you want to make a Google Map for a term then you would have to do this in the template file.

I would like to see both view and load in the $op. hook_taxonomy should be similar to hook_nodeapi to allow for easy coding against taxonomies and terms. Actuallt it should be named hook_taxonomyapi to be consistant.

And I guess that this is too late for D7 now... so perhaps for D8?

nancydru’s picture

@MiMe: there is already a hook_taxonomy, it just doesn't implement op=load. No, it's not yet too late for D7.

@dman: there is at least one module (Taxonomy Extra?) that does nothing but modify Taxonomy. There is also Taxidermy, which I think gives this capability.

nancydru’s picture

As a matter of fact, I believe this is included in #306224: EOL Taxonomy sprint: add proper taxonomy term hooks.

dman’s picture

Heh Nancy. Check the dates.
Yes, catch, bangpound and I drew up the roadmap for HOOK_term_ACTION together at the EOL Taxonomy Sprint - taxidermy was then written as a backport of the idea while term handling in core went forward into D7.
In the meantime I worked with a patched version of taxonomy_enhancer which is probably what you are thinking of. STILL NOT LEGALLY D6 - due to lack of maintainer..

Our use-case was attaching a GUID to term data.

I've gone off using taxonomy_enhancer, and instead now use a mutated version of node_auto_term for my term data storage.

webchick’s picture

nancydru’s picture

That's what I thought. I was responding to MiMe's post.

MiMe’s picture

Hi all!

@NancyDru: I know that hook_taxonomy eists... that's why I wrote "hook_taxonomy should be similar to hook_nodeapi" :)

Great that it's fixed!! :) But, there always a but... I guess it could be implemented into hook_taxonomy, like the hook_nodeapi?

webchick’s picture

In Drupal 7, hook_nodeapi is now hook_node_load(), hook_node_insert(), hook_node_update(), etc. And hook_taxonomy is now hook_term_X(), hook_vocabulary_X(). So, no, it will not be implemented in hook_taxonomy() since that doesn't exist anymore, but the functionality you're looking for is the same.

nancydru’s picture

@Mime: Indeed, there is a move away from hook_xxx(op=yyy) to individual cases like hook_xxx_op1, hook_xxx_op2 for performance.

MiMe’s picture

Are there any plans for view hooks for terms and vocabularies in Drupal 7, that would work in the same manner as hook_node_view but for vocabularies and terms?

webchick’s picture

All of our plans are here. :) http://drupal.org/project/issues/drupal feel free to add one of your own if someone hasn't already.

Status: Fixed » Closed (fixed)

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