Calling actions manually

Actions are a convenient way to package functionality in reusable chunks that can be called upon specific events. Countless modules expose actions, and at least the following consume them:

  • Trigger
  • Rules
  • Workflow
  • Views Bulk Operations

I found it useful to manually call actions in the business logic as well, typically during form submissions or in hook_nodeapi. Here's how I do it:

('Commission activated to author', $node, array('node' => $node));

actions_call($title, $object, $context) {
$aid = db_result(db_query("SELECT aid FROM {actions} WHERE description='%s'", $title));
actions_do($aid, $object, $context);

Beware that if you change the action's title, you will need to change your calling code as well. This is because actions don't have internal names, which is a useful design pattern that Views and CCK, for example, implement.


thank you very much for that

thank you very much for that short and fast help i was searching to know something like this but your explanation here gives me the ideas thank you