Make a Drupal action that can be used with views node operations (disable comments on node exampe)
First of all,to use this action, install http://drupal.org/project/views_bulk_operations
Next, put code like the below in any module you happen to have handy. In our case we had the agaric glue module for AgaricDesign.com. The .info file is attached, because all you need is a barebones .info and a .module file that contains something like the below. For instance, for us that means the agaric.info file attached and an agaric.module file that contains just the below PHP (with an opening <?php tag but without the closing ?> tag, per Drupal coding standards).
Note that the action API is very odd in that, contrary to most Drupal hooks which have a standard ending (and the first part of the function name is always the module name), for actions the first part of the function name is action_ followed by something that describes your action.
This creates quite the possibility of function namespace collision, so be extra sure that the action you need isn't already implemented.
<?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 '';
}
}
?>Resolution
More like this
- Agaric wants to disable comments for nodes, en masse, retroactively
- Ask Agaric: User registration is disabled? How can I let people sign up?
- Using the taxonomy term associated with a node as an argument in a view
- Make nodes easy to edit, even when they are embedded in a panel or teaser ist
- Can't use taxonomy_node_get_terms immediately after terms inserted
Comments
Post new comment