I have a 'custom' CCK fieldtype module that basically links up a nodereference field with a hidden taxonomy term reference. This allows me to keep a different reference for each term in my taxonomy.
I'm trying to build a view that displays this field. The view has terms as a filter (and as an argument in other cases). Currently, all the information in the field is displayed, but I only want to display the relevant info that is linked to the term that is the current $arg or filter for the view.
Conceptually, this is not hard and would only require adding a WHERE clause in the view query that would use the current $arg or filter. But I'm not sure which function to achieve this with, or whether it would be more straightforward to expose my field to views or to use one of the views hooks to alter the query before it gets processed.
My hunch is that using a views hook would be easier, but I'm having trouble figuring out which one to use. views_query_alter() makes the $query object available but is not run each time (which i need because of the dependence on the $arg, no?). the other hooks run each time the view is called, but i can't tell how to manipulate the query from within these functions since it seems like only the view is available?
any views guru advice would be very much appreciated. thanks!
Comments
understanding the problem a little better
After walking the views code a little bit I'm realizing that the views query works differently than I had imagined and adding a where clause for a field doesn't make any sense. So let me re-state the problem.
I wrote a custom CCK fieldtype that extends the nodereference table to include a term reference. It is always a multiple value field. Table structure is, therefore:
In table views that take a taxonomy term as an exposed filter or an argument, this field should only display values where field_name_tid = (args['tid'] || filter['tid']). Currently, it seems that doing this from a customized views field handler would do trick.
But how do I get the tid from the current view into a custom field handler function?
If this is not the right way to be thinking about this problem then please let me know! I'm desperate as this is essential funcitonality for my site.
what about cck
after another careful look at the arrays passed to view field handlers, i found that $fielddata['vid'] holds the id of the view being called.
now the trick is to get this 'vid' passed into a formatter for a cck type.