Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Views Bulk Operations & Actions (plus configurable secondary page) in Drupal 5

Parent Feed: 

Here's a quick example of writing an Action (5.x-2.x, which is a backport of 6.x's API style) for Views Bulk Operations. It allows you to assign selected users from a view (Usernode) and assign them to selected Organic Groups from a secondary page.

<?php
/**
* Implementation of hook_action_info().
*/
function go_views_bulk_ops_action_info() {
  return array(
   
'go_views_bulk_ops_action' => array(
     
'description' => t('Add Selected Users to OG'),
     
'type' => 'node',
     
'configurable' => TRUE,
      ),
  );
}function
go_views_bulk_ops_action_form($context) {
 
$ogs = og_all_groups_options();
 
$form['ogs'] = array(
   
'#title' => t('Groups'),
   
'#type' => 'checkboxes',
   
'#options' => $ogs,
   
'#description' => t('Select which Groups the selected users will join'),
  );
  return
$form;
}function
go_views_bulk_ops_action_validate($form_id, $form_values) {}function go_views_bulk_ops_action_submit($form_id, $form_values) {
  return array(
'ogs' => $form_values['ogs']);
}function
go_views_bulk_ops_action(&$node, $context) {
   
$uid = db_result(db_query("select uid from {usernode} where nid=%d", $node->nid));
    foreach(
$context['ogs'] as $gid){
        if(
$gid)
           
og_save_subscription($gid, $uid, array('is_active' => 1));
    }
}
?>
Author: 
RSS Tags: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web