Can somebody explain to me what the difference is between an object and context within the advanced action setup please.

I understand what an object is but am failing to understand what context is.


  • What is "the advanced action setup"?
    – Letharion
    Commented Jul 18, 2012 at 9:22

3 Answers 3


If you are talking about the $context variable (and I think you do), then the official description is: an associative array containing extra information about what triggered the action call, with $context['hook'] giving the name of the hook that resulted in this call to actions_do() (from here: http://api.drupal.org/api/drupal/includes!actions.inc/function/actions_do/7)

But if you want to understand it better, this page is very useful: http://www.sysarchitects.com/node/47


The context is used to identify how the action is being triggered so that, if necessary, it can handle the object differently — e.g. an action that has to do different things depending on whether a node is being inserted for the first time or updated.


Drupal supports a trigger/action system. So you can easily give drupal some object id(s) and say I want these Actions to occur to this object, at some time or context.

Here is a small example from some code I run via drush in a php-eval:

$q = new EntityFieldQuery();
$types_to_publish = array('page');
$q->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', $types_to_publish, 'IN');
$results = $q->execute();
foreach ($results['node'] as $node) {
  $current_node = node_load($node->nid);
  $migrator_user = user_load_by_name('d7migrator_user');
  $current_node->uid = $migrator_user->uid;
  $actions = array('node_publish_action', 'node_save_action');
  $context['node'] = $current_node;
  actions_do($actions, $current_node, $context, NULL, NULL);
drupal_set_message('Done publishing content.');

I do this because I'm migrating some node via node_export and then apply the Workbench module and currently need to re-save nodes to that Workbench can properly set the publish state for the given NIDs. We dont need to supply a $context here beyond the node because I'm not hooking into the lifecycle of a page request or form POST processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.