This is sort of a regression, I think.

With the former monolithic hook_nodeapi, you could act on insert and update together -- in other words when new data is arriving in the node. There are cases where you don't need to distinguish whether the actual node is new or not, you just want to act when stuff happens. Userpoints might be one example; any module in general that wants to do something with fresh node data.

It used to be you could say:

// implementation of hook_nodeapi
case 'insert':
case 'update':
  // do stuff that applies to both
  break;

And now you can't.

Comments

mlncn’s picture

Status: Active » Closed (works as designed)

True, there is a slight loss of convenience here.

It is nearly as easy, arguably clearer, and takes about the same amount of code (given that the switch statement and case calls can be removed) to abstract the common code into another function:

/**
 * Implements hook_node_insert().
 */
function foo_node_insert($node) {
  _do_stuff_that_applies_to_both($node);
}

/**
 * Implements hook_node_update().
 */
function foo_node_update($node) {
  _do_stuff_that_applies_to_both($node);
}

benjamin, agaric