I have created a custom action to assign users to organic groups using the functions:
function ccn_groups_action_info() {
return array(
'bulk_group_assignment_action' => array(
'type' => 'user',
'label' => t('Assign Users to Groups'),
'configurable' => TRUE,
),
);
}
function bulk_group_assignment_action_form($context) {
$roles = array();
$e_type = 'node';
$results = db_query("select gid, label from og where entity_type = :e_type order by label",
array(':e_type' => $e_type,),
array('fetch' => PDO::FETCH_ASSOC,));
foreach ($results as $row){
$roles[$row['gid']] = $row['label'];
}
$form['add_roles'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Available Groups'),
'#description' => t('Choose one or more groups you would like to assign to the selected users.'),
'#options' => $roles,
'#size' => 20
);
return $form;
}
function bulk_group_assignment_action_validate($form, $form_state) {
if (!$form_state['values']['add_roles'] ) {
form_set_error('add_roles', t('You have not chosen any group to add. Please select something to do.'));
}
}
function bulk_group_assignment_action_submit($form, $form_state) {
return array(
'add_roles' => array_filter($form_state['values']['add_roles']),
);
}
function bulk_group_assignment_action(&$user, $context) {
$usr = $context['user'];
$roles = $context['add_roles'];
$uid = $usr->uid;
$name = "og_membership_type_default";
$etid = $uid; //Supplied from $context
$entity_type = "user";
$gid = "666"; //Supplied from $context
$state = 1;
$created = time();
foreach($context['add_roles'] as $gid){
$nid = db_insert('og_membership')
->fields(array(
'name' => $name,
'etid' => $etid,
'entity_type' => $entity_type,
'gid' => $gid,
'state' => $state,
'created' => $created,
))
->execute();
}
}
These functions work as expected, providing a form where the user can select 1 or more groups, along with a view where the user can select users to assign to the selected groups. Additionally the user performing the operation receives a warning if no groups are selected or if no users are selected.
And finally, before performing the operation, the user performing the operation receives a confirmation page listing the users selected for assignment.
Once completed the user receives a message indicating that the operation has bee performed for n number of items.
Clients being clients want something different on the confirmation page and on the post-processing message. Specifically, on the confirmation page, the client wants to see the groups selected as well as the users selected, and on the post-processing page wants to see the number of the groups to which the users were assigned.
Despite hours upon hours of research including examination of the VBO code itself (where I found the code that produces the confirmation page and the post processing message, I've been unable to determine any way to modify the confirmation message or the post processing page.
Any thoughts or pointers would be greatly appreciated!