I have a requirement to allow the Drupal content/node administrator to choose if a notification should go out for the particular update being done. The case made is say you correct a mis-spelling or something in a node that shouldn't be worth blasting out an alert to all users watching a post. This would allows the content administrator to choose if the update should submit a notification or not.

I was going to add a hook/patch to the module to allow an override point but there may be a compromise that doesn't require altering the module.

I noticed the notification send process in the module does the following code check:

// Are email notifications enabled?
  $email_notifications = variable_get('watcher_email_notifications_enabled', TRUE);
  if (!$email_notifications) {
    return FALSE;
  }

That said I plan to meet this requirement by:

  • Adding a custom module that implements hook_form_BASE_FORM_ID_alter to add a temporary form element to the node edit form which will be a checkbox to ask the editor if the form should send a notification or not (not checked by default).
  • Add another hook to the custom module implementing hook_node_update hook_node_insert that both call the same function that will check for that temporary checkbox being checked.
    If the checkbox is NOT checked it will then call variable_set to set the watcher_email_notifications_enabled value to FALSE. That will then allow the notification send to terminate before sending. If it is checked then the variable is set to TRUE and the notification is sent as normal. (you must ensure this hook runs before the Watcher modules update/insert hook using hook_module_implements_alter in your custom module to set Watcher to run before the custom module as far as order.

Once all that is done the process will be:
User edits a node with watcher enabled.
User selects the "Send notification" checkbox. (If not checked no notification will be sent).
When checked the variable will be set to allow the notification send to proceed. (The variable will always hold the value of the previous decision so it will be set to True or False during each node add/edit save.)

I will update this and possibly add some code here after I have implemented it.

Comments

kholloway created an issue. See original summary.

kholloway’s picture

Issue summary: View changes