Search code examples
drupalhookdrupal-7

Post-save callback?


How do I execute a function every time a node is being updated? I tried to use hook_nodeapi, but it looks like that the hook is removed from Drupal 7.

What I want to do is,

  1. add a new field to my content type called 'main image (bool)' to let the admin set a main image.
  2. I am going to use Views module to display nodes, but order nodes by 'main image' field and added date.
  3. so that the first node is always the main image.

to do this, I need to make sure that there is always only one node with 'main image' set to true.


Solution

  • The hook has not been removed but splitted up into separate hooks for each $op.

    See: http://api.drupal.org/api/search/7/hook_node

    For post-save, you want hook_node_insert() and hook_node_update()