[development] About hook_action_info()

Vandyk, John K [ENT] jvandyk at iastate.edu
Tue Jul 13 13:46:44 UTC 2010


That does not look like an implementation of hook_action_info(). For an example implementation, see

http://api.drupal.org/api/function/hook_action_info/6

It looks like you are actually writing an action. In that case, the first parameter is populated by the native object that the action is working on. For example, if you are triggering an unpublish action when a node is edited, the object that you are working on is a node, and the trigger system will send the node object along to the action call as the first parameter.

However, if you want to do something crazy like unpublish a node when a comment is submitted, you are acting on a comment object, not a node object. If you run an unpublish node action in that case, the trigger system will expend a little effort trying to make sure that the unpublish-a-node action (which works on nodes) gets a node. See

http://api.drupal.org/api/function/trigger_comment/6
http://api.drupal.org/api/function/_trigger_normalize_comment_context/6

Since some actions can be called in multiple contexts, you will see them doing gyrations like this:

http://api.drupal.org/api/function/system_message_action/6

The short answer is, ask yourself whether your action will ever be used in a weird context, and if you might have to pluck the $node from the $context or do a node_load() from some information in the context that could lead you to the node.

On Jul 13, 2010, at 12:52 AM, icerain wrote:

> When i implement hook_action_info(), i found the first para *$node* is empty.
> My question is 
> function mymodule_myaction_action(&$node, $context = array()) {
>     $node = $context['node']; // should this line be added?
> ...
> }
> Or something else error?
> -- 
> A decathlon Drupal developer & programmer
> http://blog.eood.cn/



More information about the development mailing list