Disable Comments by Default

A quick post here. Often times I find myself building sites that have a blog and thus use the Comment module that ships with Drupal. That all works great. The problem is, later when I'm building out other content types, say "Photo Galleries":http://www.chrisfree.me/2010/02/create-drupal-photo-gallery-using-flickr-cck-views, I more often than not wish to disable comments on those node types. No problem, right? Just disable comments and get on with it. Well no - it's not all right with me. I think comments should be disabled by default or at the very least, the Comments fieldset should be expanded by default so that you're reminded to turn them off. Unfortunately, neither of these things are true on Drupal 6.

So instead of "bitching about it":http://twitter.com/chrisfree/status/16182217533 again on Twitter, I decided to just write the 7 line module that would fix this for me. Here's the code:

<?php

/**
*  Implementation of hook_form_alter().
*/
function form_overrides_form_alter(&$form, $form_state, $form_id) {
  switch($form_id) {
    case 'node_type_form':
      $form['comment']['comment']['#default_value'] = 0;
      break;
  }
}
?>

I've attached an archive of the module below as well.

Once you've got this worked into your existing form overrides or installed as a new module. Be sure to clear your cache - otherwise you won't see the change.

So now, any time you create a new node type, the comments will be disabled. Sick.

AttachmentSize
form_overrides.zip1.62 KB
Categories: 

Comments

An alternative would be to set it in your installation profile: variable_set('comment_book', COMMENT_NODE_DISABLED); variable_set('comment_image', COMMENT_NODE_DISABLED); variable_set('comment_page', COMMENT_NODE_DISABLED); with the basic format of variable_set('comment_*content type system name*', COMMENT_NODE_DISABLED);

Great idea Chris! I run into this issue quite frequently with some of my sites that have numerous content types (e.g. I create a new content type via CCK or whatever, and have to remember to circle back and disable comments for it initially).