Display a link in a node that will execute an "action" (or anything else on the php side) for that node?
I've been using Drupal for a few years now. I support about 15 Drupal-based web sites. Most of them are simple and don't require a lot of customization beyond the standard Drupal modules and are mostly theme work. However, I have hit a snag.
I'm somewhat new to php (though a professional programmer who is looking to give back to the Drupal community at some point) but I think I have the basics of how Drupal works at least on the surface.
I want to know how I can put a link on a node (CCK node in this case) that will get me back to the php code side so I can perform operations on that particular node.
For example, say I had a node named Car. I want the owner of that node to be able to click on a link named Honk. When that user clicked, I would like some code (probably in a module) to run and give me that node ID. I can take it from there.
Another example: say I wanted to add a link "Mark as Funny" to a blog post and I wanted some special php code to run when any viewer clicked on it.
This seems like something I should already know how to do and it is probably something fundamental in the Drupal API that I somehow managed to overlook. I've been trying to figure it out searching here and Google for over two weeks (off and on of course - I did sleep and do a few other things) with no luck.
I have installed and played with various combinations of workflow, actions, workflow-ng, and others, and I *think* I could hack it up to do what I want specifically. But what I would really like is to know to do this in general as I'm pretty sure I'll run into similar situations.
Thanks so much for helping out.

I wonder if the Flag module
I wonder if the Flag module would help.
In some cases it would.
Thanks for the suggestion and it would help with my example. It's just that I wanted to be able to do it in general.
Typical: as soon as I post a question...
I figured out what I was looking for. It's the menu stuff in the API. It was the name "menu" that threw me off. I wasn't looking for anything in a "menu" so ... anyway.
Turns out, in case any reader was interested that the way you do this is my handling hook_menu. You get to register paths and have those paths execute other code in your module. You can pass whatever you like: node id for example.
I don't know why after weeks of hunting I found it less than two hours after I posted the question.
First, in theory, I'd warn
First, in theory, I'd warn that according to the HTTP spec and 'best practices' it is best to avoid cases where clicking a link (a GET) invokes an actual action or change to the database. We say that GETs should be 'idempotent' . See the spider of doom for why.
That said, in the world of AJAX and Digg and edit UIs... you can make up your own mind about whether that guideline applies to you.
So ...
The quick way - if I understand your question - is to create a menu router entry that triggers a callback which runs your code.
Looking at node.module node_menu() for a few clues...
<?php
function honk_menu() {
$items = array();
$items['node/%node/honk'] = array(
'title' => 'Honk',
'description' => 'Honk this node.',
'page callback' => 'honk_do_honk', // function to call
'page arguments' => array(1), // the first parameter - %node
'access callback' => 'node_access',
'access arguments' => array('update', 1), // anyone with edit rights on this node can do this
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* @return the text that is displayed on the page when the button is pressed
*/
function honk_do_honk($node) {
return "<b>Honked</b> '{$node->title}' !";
}
?>
Does the trick.
I used a MENU_LOCAL_TASK so it shows as a tab, but you can change that to a MENU_CALLBACK and it will be invisible, and you construct the link to the URL yourself.
Is that a start?
Longer and other ways using actual 'actions' and the action api are also possible (and possibly more useful), but this answers the question as stated.
.dan.
Exactly what I did.
Your suggestion was almost exactly what I had done. Your example was very helpful as well. I had only looked at the examples in the documentation.
I had not yet seen the way you roped in the arguments when you set up the menu callback. Currently, I am pulling them all out manually. I will look around a bit more to make sure I understand it all very well. (Was that a Drupal 6 thing? I'm in 5 for this particular project.)
I do understand and agree with the suggestion for idempotence in GET operations. I can see all sorts of issues there.
In my actual cases, I will make sure this is managed in code.
reading the real code is handy also.
I just looked at node.module, because I knew it supplied node/n/edit in the same way that we wanted node/n/honk
Those menu args are Drupal6, yes. So my eg is not totally relevant then.
in D5 you still have to use arg(1), arg(2)
it all works out.
.dan.