You are here

function spaces_og_user in Spaces 5.2

Same name and namespace in other branches
  1. 6.3 spaces_og/spaces_og.module \spaces_og_user()
  2. 6 spaces_og/spaces_og.module \spaces_og_user()

Implementation of hook_user().

File

./spaces_og.module, line 499

Code

function spaces_og_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'form':
      if ($category == 'account') {

        // Add the groups selector to the user form.
        $form = og_user('register', $edit, $account, $category = NULL);
        $form['og_register']['#weight'] = 5;
        $form['og_register']['og_register']['#default_value'] = array_keys($account->og_groups);
        return $form;
      }
      break;
    case 'update':
      if (is_array($edit['og_register'])) {

        // Process groups selections.
        $active_groups = array_keys(array_filter($edit['og_register']));
        foreach (array_diff($active_groups, array_keys($account->og_groups)) as $gid) {
          $return = og_subscribe_user($gid, $account);
          if (!empty($return['message'])) {
            drupal_set_message($return['message']);
          }
        }
        foreach (array_diff(array_keys($edit['og_register']), $active_groups) as $gid) {
          og_delete_subscription($gid, $account->uid);
        }
      }
      break;
  }
}