Documentation states:
> This hook is invoked from node_delete_multiple() after the node has been removed from the node table in the database, after the type-specific hook_delete() has been invoked, and before field_attach_delete() is called.
However, as #921944: error messages on tracker page - tracker_node_delete() does not correctly act on node deletion shows, the above is not true. The following code in tracker module still retrieves a node:
$node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
The code in node.module confirms this:
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
module_invoke_all('node_delete', $node);
module_invoke_all('entity_delete', $node, 'node');
field_attach_delete('node', $node);
// Remove this node from the search index if needed.
// This code is implemented in node module rather than in search module,
// because node module is implementing search module's API, not the other
// way around.
if (module_exists('search')) {
search_reindex($nid, 'node');
}
}
// Delete after calling hooks so that they can query node tables as needed.
Marking as major as this has implications for all implementing modules, and I've no idea which of the code or docs is correct...
Comment | File | Size | Author |
---|---|---|---|
#7 | 988030-7-hook_node_delete.patch | 2.59 KB | linclark |
#2 | hook-node-delete.patch | 763 bytes | mr.baileys |
Comments
Comment #1
marcingy CreditAttribution: marcingy commentedThe code is correct the change was introduced here http://drupal.org/node/890790
Comment #2
mr.baileysDoc update.
Comment #3
marcingy CreditAttribution: marcingy commentedI'm happy to mark this rtbc.
Comment #4
jhodgdonThis patch is OK but incomplete.
http://api.drupal.org/api/drupal/modules--node--node.api.php/group/node_...
needs to be updated as well with this information.
Comment #5
jhodgdonAlso, the node API page needs to mention that hook_entity_delete() is also called, apparently.
http://api.drupal.org/api/drupal/modules--node--node.module/function/nod...
Are there other entity hooks that have been added to other operations on that page too?
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedI'll have a new patch for this shortly.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedThis patch builds upon the previous patch, which changed the order of the functions listed in the comment for hook_node_delete.
It adds hook_entity_delete to the comment for hook_node_delete and moves the reference to node deletion in the larger list of function calls for hook_node_delete, as suggested by jhodgdon.
It also adds to the large list the following hook invokations, which were missed before.
For some reason, "Viewing multiple nodes" had hook_node_view_alter listed and "View single node" did not. Since hook_node_view_alter is called from node_view, I assume that both should have the alter hooks listed.
Comment #8
jhodgdonExcellent work! Let's get this into d8 and d7 please. Thanks linclark and mr.baileys.
Comment #9
Dries CreditAttribution: Dries commentedCommitted to 7.x and 8.x.