Action to change comment status on a node

robertDouglass - June 27, 2006 - 10:31
Project:Actions
Version:4.7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

<?php
/**
* Implementation of a Drupal action.
* Configurable action to set the comment status
*/
function action_comments_status($op, $edit = array(), &$node) {
   
$settings = array(t('Disabled'), t('Read only'), t('Read/Write'));
  switch(
$op) {
    case
'metadata':
      return array(
       
'description' => t('Change comments status'),
       
'type' => t('Node'),
       
'batchable' => true,
       
'configurable' => true,
      );
   
// return an HTML config form for the action
   
case 'form':
     
$form['comment_settings']['comment'] = array(
       
'#type' => 'radios',
       
'#parents' => array('comment'),
       
'#default_value' => $edit['comment_settings'],
       
'#options' => $settings,
      );
      return
$form;
   
// validate the HTML form
   
case 'validate':
      return
in_array($edit['comment_settings'], $settings);
   
// process the HTML form to store configuration
   
case 'submit':
     
$params = array('comment_settings' => $edit['comment']);
      return
$params;
    case
'do':
     
$node->comment = $edit['comment_settings'];
      if (!
$edit['defer']) {
       
node_save($node);
      }
     
$message = t('Set comments on node id %id to %status', array('%id' => intval($node->nid), '%status' => $settings[$node->comment]));
     
watchdog('action', $message);
      break;
  }
}
?>

#1

mfredrickson - June 28, 2006 - 19:18

This should be added to the Actions Snippets page:

http://drupal.org/node/48737

#2

robertDouglass - June 28, 2006 - 21:31

I was rather hoping it would get committed to actions.inc.

#3

jvandyk - September 8, 2006 - 20:56

If Drupal core's comment status settings are Disabled|Read only|Read/Write then for consistency with the way we treat other built-in node status settings I think we need three actions here:

Set comment status to Read-Only
Set comment status to Disabled
Set comment status to Read/Write

#4

Peloose - March 27, 2009 - 07:39

Can I information (step by step) to add custom action?
regards

 
 

Drupal is a registered trademark of Dries Buytaert.