I'm using a rule with Rules Event "Before saving content", but this rule is also executed when I delete the node.

I'm recalculating some fields, I don't need to do this when the node is going to be deleted.

How can I know when the node is going to be deleted? I'm coding the rule with hook_rules_action_info.

  • then use after updating content.
    – No Sssweat
    Commented Sep 24, 2015 at 1:56
  • @NoSssweat : I doubt your suggestion in the prior comment will make a lot of difference ... Commented Feb 3, 2017 at 17:28

1 Answer 1


Have a look at this rule (in Rules export format):

{ "rules_before_saving_content_but_not_when_deleting" : {
    "LABEL" : "Before saving content but not when deleting",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "DO" : [
      { "drupal_message" : { "message" : "The path of the content being saved = [site:current-page:path]" } }

If you request an edit a node (say with nid=71) your path will be node/71/edit. If you then save the node by hitting the Save button, the above rule will show a Drupal message like so:

The path of the content being saved = node/71/edit

If you request an edit a node (say with nid=72), your path will be node/72/edit. But if you then decide to delete (instead of save) the node by hitting the Delete button, then no Drupal message (similar to the previous scenario above) will be shown.

This (rather basic) Rules debugging scenario, leads me to believe that, out-of-the-Rules-box, Rules Event Before saving content does NOT get triggered when a node is deleted. So whatever problem you are experiencing (when a node is deleted), it must be because of something else happening in your site, in your custom rule, or your custom code of your rule. If I was to further investigate your issue, I'd start "Rules debugging", as explained in the answer to "How can I display the value of a variable inside a condition?".

PS: a quick-and-dirty workaround for whatever issue you're experiencing, might be to check the results you get by adding an extra Rules Condition to check if the (saved) node will still have status "published" (assuming a deleted node is no longer marked as "published").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.