~ 1 min read

Drupal and how to disable notifications for programmatic node updates

share this story on
Programatically working updates on Drupal nodes with node_save() hook

More than often, we Drupal developers find ourselves doing programmatic node modifications via the

node_save()

function. If you’re doing that as well as have messaging and notifications modules enabled in your site then given the case that your users have subscribed to content-type updates and you’re doing these ‘behind the scenes’

node_save()

stuff then you’re effectively spamming them with email updates each time you run that function.

To mitigate this issue, when saving a node programmatically you can set an attribute for the notifications module to understand that it needs not to send updates for this operation. It’s a quick and easy one:

function probably_your_hook(&$node) {
 // ... code ... 
 
 // Disable announcements for this operation
 $node->notifications_content_disable = 1;
 node_save($node);
 
 // ... code ... 
}