1 node.api.php hook_node_presave(Node $node)

Act on a node being inserted or updated.

This hook is invoked from node_save() before the node is saved to the database.

Parameters

Node $node: The node that is being inserted or updated.

Related topics

File

core/modules/node/node.api.php, line 636
Hooks provided by the Node module.

Code

function hook_node_presave(Node $node) {
  if ($node->nid && $node->moderate) {
    // Reset votes when node is updated:
    $node->score = 0;
    $node->users = '';
    $node->votes = 0;
  }
}