/**
* 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;
}
}
Comments
Comment #1
mfredrickson commentedThis should be added to the Actions Snippets page:
http://drupal.org/node/48737
Comment #2
robertdouglass commentedI was rather hoping it would get committed to actions.inc.
Comment #3
jvandyk commentedIf 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
Comment #4
Peloose commentedCan I information (step by step) to add custom action?
regards
Comment #5
pomliane commentedThis version of Actions is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.
This issue has been automagically closed by a script.
Comment #6
donpwinston commentedThe most strait forward way is to use hook_node_presave($node) assumming the comment status depends on the content of the node.
( hook_form_alter is crazy)
This is for individual nodes.