Add "Notify me..." checkboxes to node and comment authoring forms

starkos - February 12, 2009 - 19:36
Project:Watcher
Version:6.x-1.0-beta3
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:by design
Description

I added a checkbox to the node and comment authoring forms: "Notify me of replies or changes to this post". This saves a step when creating new content, enabling a subscribe (or unsubscribe) at the same time as the content is posted. It also helps people who are using to another system (like Wordpress, phpBB, or every system that isn't drupal) that uses similar checkboxes.

It didn't take much code (for D6):

<?php
function _watcher_node_form_submit($form, &$form_state) {
  global
$user;
 
$form_id = $form['form_id']['#value'];
  if (
preg_match('/_node_form$/', $form_id) || $form_id == 'comment_form') {
   
$nid = $form_state['values']['nid'];
    if (
$form_state['values']['watcher_enable']) {
     
_watcher_user_set_watching_node($nid, $user);
    } else {
     
_watcher_user_unset_watching_nodes(array($nid), $user);
    }
  }
}


function
watcher_form_alter(&$form, $form_state, $form_id) {
  global
$user;
  if (
preg_match('/_node_form$/', $form_id) || $form_id == 'comment_form') {
   
$nid = $form['nid']['#value'];
    if (
$user->uid && user_access('use watcher') && (!$nid ||_watcher_node_type_enabled($nid))) {
     
// See if the user is already watching this node
     
$watching = _watcher_user_is_watching_node($user, $nid);
   
     
// Add "Notify me..." checkbox to the form
     
$form['watcher_enable'] = array(
       
'#type' => 'checkbox',
       
'#title' => t('Notify me of replies or changes to this post'),
       
'#default_value' => $watching,
      );
   
     
// Add a submit hook to process the checkbox
     
$form['#submit'][] = '_watcher_node_form_submit';
    }
  }
}
?>

#1

solipsist - February 12, 2009 - 19:47
Status:needs review» by design

There are already settings for this in the user settings, it makes the user automatically watch any node he or she creates or comments on. You can set them as defaults for all users if you like.

Thanks for sharing but I won't implement this as with it, Watcher will be just more or less a clone of all existing notification modules. I will however consider adding some text to comment forms informing users if autowatching is enabled, providing a link to their settings page.

#2

starkos - February 13, 2009 - 16:16

This isn't autowatching. This is giving the user the *option* to watch a node at the time they author it, or add a comment to it. Otherwise a user has to author a node/comment, submit it, and then find and click the "watch" link.

Or, turn on autowatching, and then find and click "Stop watching" for every post they don't intend to follow.

Not a big deal if you don't want to integrate it; it is easy enough to tack on after the fact. Sure seems like an easy win to me, especially for visitors accustomed to other systems where this presentation is the norm.

#3

solipsist - February 13, 2009 - 18:57

You make a good point. I'll find a way to implement this that rhymes well with the overall design. I want to keep Watcher as lean as possible and with all feature requests popping up, I try my best to be strict about what I add.

Thanks for your input!

#4

starkos - February 16, 2009 - 19:12

Upon further testing, I discovered that the code above has a number of glaring holes (d'oh - I should have slept on it before I posted). There is a new, improved version attached which addresses the obvious flaws and seems to work under all submit combinations I could think up.

I appreciate you considering it for inclusion into your module, and I understand what you mean about keeping it lightweight. To that end, I've packaged it up as a separate module "watcher_checkboxes", in addition to the other fixes I mentioned.

AttachmentSize
watcher_checkboxes.tar_.gz 1.46 KB

#5

bflora - June 20, 2009 - 02:43

WOuld this work for D5?

#6

scottrigby - August 17, 2009 - 01:54

@starkos: would the Comment Notify module work for what you need? http://drupal.org/project/comment_notify

#7

solipsist - August 18, 2009 - 05:59

I'll look into implementing this. Stay tuned.

#8

yngvewb - September 1, 2009 - 12:15

I'm tuning in :-) Is this feature coming in a dev version?

#9

solipsist - September 2, 2009 - 17:22

If you really want this feature, seek me out here at Drupalcon Paris and buy me a beer and we'll do some coding. :) You'll find me, or someone who knows how to find me, at the NodeOne table in the sponsors room.

#10

askibinski - October 23, 2009 - 12:43

I guess there was no beer? ;)

I also think this would be a great addition.

From fitst-hand experience on a site with watcher and a lot of comments everyday:

According to the many comments versus the amount of people who are actually watching posts, my guess is many people who post a comment overlook the watcher-link, don't understand it, or don't complete the form (anonymous users).

And extra checkbox below the comment-form would solve this, because anonymous users wouldn't have to leave their contact info twice.

#11

starkos - October 28, 2009 - 18:39

@askibinski, @yngvewb - I've been using the module in #4 for months now with no trouble. It isn't part of the official release, of course, but it has been working well nevertheless.

@scottrigby - I looked at Comment Notify, but discarded it. Off the top of my head, I think it required a comment before your could follow, and I liked the Watcher presentation better. It has been a long time since I looked at it though, and I could be remembering incorrectly.

#12

askibinski - November 1, 2009 - 12:10

@starkos allright, but will Solipsist welcome a patch which implements the functionality of #4 so this could be a part of the official release ?

#13

solipsist - November 1, 2009 - 12:33

Sure, go ahead. A patch would be most welcome. Please diff against CVS. I'll try and get some time to spend on Watcher and my other modules so this gets in.

#14

starkos - November 4, 2009 - 21:14

I kind of like the fact that it is a separate module, and can be turned on or off. Could it be kept as-is, and included in the watcher package (like the way CCK includes separate modules for all the different field types)?

 
 

Drupal is a registered trademark of Dries Buytaert.