I'm suggesting adding an argument handler for node id. This enables a view to narrow itself down to a single node.
Why do that, you ask, when a list view could just as easily link to ?q=node/NID to show the node?
Well, in my case I'm building views with args that narrow the search first by taxonomy, then down to a single node. And I also have a navigation block that indicates where the user is browsing. So, if my user visits ?q=myview, then narrows to ?q=myview/4 (tid = 4) my navigation block builds a mock-menu to show them where they are. Finally the user picks a node. If the URL is ?q=myview/4/10 (nid=10) then my navigation block stays intact. But if the URL is ?q=node/10, my navigation block goes away.
Similarly, I could be defining a custom them for the node when browsing through myview, or I could handle the breadcrumbs differently.
So if you agree its useful, here's the code I'm using in my module:
function ocp_project_handler_arg_nid($op, &$query, $argtype, $arg = '') {
switch($op) {
case 'summary':
$query->add_field("title");
$query->add_field('nid');
$fieldinfo['field'] = "node.nid";
return $fieldinfo;
break;
case 'filter':
$where = db_escape_string($arg);
$query->add_where("node.nid = '$where'");
break;
case 'link':
$q = $_GET['q'];
return l($query->title, "$q/".$query->nid);
case 'title':
return $query;
}
}
The one part I really don't like is using $_GET['q'] to build the link. I'm open to suggestions there.
Comments
Comment #1
merlinofchaos commentedYea, $arg has the data you need for the path. In fact, using ?q= will get you bad data in some instances, at least for breadcrumbs. Not that you're likely to ever have a view beneath this. It also needs to look up the title (I know, this seems counter-intuitive but 'title' is often called outside the actual query) for the 'title': case. And when using add_field() you should always use table.field
Other than that, I think this is a fine idea. I'll plug it in.
Comment #2
merlinofchaos commentedSomewhere along the way this went in, and I completely forgot about it.
Comment #3
(not verified) commented