Disable Comments on Nodes Action: Example for use with Views Node Operations

Last modified: December 31, 2007 - 12:45

This code, or code like it (this, in turn, is modeled on actions module's action.inc file) needs to be placed in a Drupal module– any module, but presumably one you made! With Actions module also installed, it will automatically begin working with Views Bulk Operations.

Note that the function name does not change to fit your module name, contrary to customary Drupal practice, but must begin with "action_" (some more information on action and making a module here).

<?php
/**
* Implementation of a Drupal action.
* Disable comments for a node.
*
*/
function action_node_disable_comments($op, $edit = array(), &$node) {
  switch(
$op) {
    case
'metadata':
      return array(
       
'description' => t('Disable comments for node'),
       
'type' => t('Node'),
       
'batchable' => true,
       
'configurable' => false,
      );

    case
'do':
     
$node->comment = '0';
      if (!
$edit['defer']) {
       
node_save($node);
      }
     
watchdog('action', t('Disabed comments on node id %id', array('%id' => intval($node->nid))));
      break;

   
// process the HTML form to store configuration
   
case 'submit':
      return
'';
  }
}
?>

Upgrade to D6?

leoklein - August 12, 2009 - 00:26

Would be great. I need an action that either turns on comments or turns them off.

 
 

Drupal is a registered trademark of Dries Buytaert.