Use realname when admin adds users to Organic Groups

SamRose - June 9, 2009 - 14:03
Project:RealName
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I am trying to figure out how to replace user_load() with realname_get_user($uid) so that an organic group admin can use the realname to add users to a group. The functions that I am overriding (originally from og.module):

<?php
function ogrealname_og_add_users($form_state, $group_node) {
 
$form['og_names'] = array(
   
'#type' => 'textarea',
   
'#title' => t('List of users'),
   
'#rows' => 5,
   
'#cols' => 70,
   
// No autocomplete b/c user_autocomplete can't handle commas like taxonomy. pls improve core.
    // '#autocomplete_path' => 'user/autocomplete',
   
'#description' => t('TEST Add one or more usernames in order to associate users with this group. Multiple usernames should be separated by a comma.'),
   
'#element_validate' => array('ogrealname_og_add_users_og_names_validate'),
  );
 
$form['op'] = array('#type' => 'submit', '#value' => t('Add users'));
 
$form['gid'] = array('#type' => 'value', '#value' => $group_node->nid);
  return
$form;
}

// An #element_validate handler
function ogrealname_og_add_users_og_names_validate($form, $form_state) {
 
$names = explode(',', $form_state['values']['og_names']);
  foreach (
$names as $name) {
   
$account = user_load(array('uid' => trim($name)));
    if (isset(
$account->uid)) {
     
$accounts[] = $account;
     
$uids[] = $account->uid;
    }
    else {
     
$bad[] = check_plain($name);
     
$err = TRUE;
    }
  }
  if (isset(
$err)) {
   
form_set_error('og_names', format_plural(count($bad), 'Unrecognized name: %bad.', 'Unrecognized names: %bad.', array('%bad' => implode(', ', $bad))));
  }
}

function
ogrealname_og_add_users_submit($form, &$form_state) {
 
// Safest option is to do a select, filter existing members, then insert.
 
$names = explode(',', $form_state['values']['og_names']);
  foreach (
$names as $name) {
   
$account = user_load(array('uid' => trim($name)));
    if (
$account->uid) {
     
$accounts[] = $account;
    }
  }
  foreach (
$accounts as $account) {
   
og_save_subscription($form_state['values']['gid'], $account->uid, array('is_active' => 1));
  }
 
drupal_set_message(format_plural(count($accounts), '1 user added to the group.', '@count users added to the group.'));
}
?>

I believe that I need to replace

    $account = user_load(array('uid' => trim($name)));

with..

    $account = realname_get_user($uid);

But, I am not 100% sure here. Looking for some advice for checking against realname when processing this form. Thanks!

#1

SamRose - October 27, 2009 - 18:43

anybody around here?

#2

SamRose - October 27, 2009 - 19:23
Status:active» closed

trying this http://drupal.org/node/517844

 
 

Drupal is a registered trademark of Dries Buytaert.