Depending on a condition I want a node's changed content not to be overwritten on the old content. That is old content should be retained and new one discarded so that node does not change.

Which action should I add? I've tried many but everytime a user saves a node, it is permanently changing the node's content.

link|improve this question

61% accept rate
feedback

1 Answer

up vote 1 down vote accepted

Create a rule for the "Content is going to be saved" event, and add a "Execute custom PHP code" action. The code you write have access to some variables by reference: $node, $node_unchanged, $user, $author, $author_unchanged, and $user.

For example, you can use the following code to set the title as it was before the node was edited.

$node->title = $node_unchanged->title;

return array('node' => $node);

screenshot

Similar code is usable in the version for Drupal 7 of the Rules module; what changes is the variables to which the code has access.

screenshot

link|improve this answer
but how do I revert to it's old content in the body? I don't find anything like $node->body – AgA Jul 26 '11 at 3:22
The old content of the body should be in $node_unchanged->body; if that is not available (but I would be surprised if it were not), then you can load the unchanged node using node_load($node_unchanged->nid). – kiamlaluno Jul 26 '11 at 3:50
Thanks, there is another way I found: redirect to another url and display error message. This can discard the changes as well. – AgA Jul 26 '11 at 4:25
feedback

Your Answer

 
or
required, but never shown

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