Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function hook_node_presave

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: The node that is being inserted or updated.

Related topics

Node API Hooks
Functions to define and modify content types.
Hooks
Allow modules to interact with the Drupal core.
8 functions implement hook_node_presave()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

book_node_presave in modules/book/book.module
Implements hook_node_presave().
EntityCrudHookTestHooks::nodePresave in core/modules/system/tests/modules/entity_crud_hook_test/src/Hook/EntityCrudHookTestHooks.php
Implements hook_ENTITY_TYPE_presave() for node entities.
entity_crud_hook_test_node_presave in modules/simpletest/tests/entity_crud_hook_test.module
Implements hook_node_presave().
forum_node_presave in modules/forum/forum.module
Implements hook_node_presave().
NodeTestHooks::nodePresave in core/modules/node/tests/modules/node_test/src/Hook/NodeTestHooks.php
Implements hook_ENTITY_TYPE_presave() for node entities.

... See full list

1 invocation of hook_node_presave()
node_save in modules/node/node.module
Saves changes to a node or adds a new node.

File

modules/node/node.api.php, line 687

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.