You are here

function spaces_og_user_groups_form_submit in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 spaces_og/spaces_og.pages.inc \spaces_og_user_groups_form_submit()
  2. 6.2 spaces_og/spaces_og.module \spaces_og_user_groups_form_submit()
  3. 7 spaces_og/spaces_og.pages.inc \spaces_og_user_groups_form_submit()

Submit handler for OG user groups form.

File

spaces_og/spaces_og.pages.inc, line 36

Code

function spaces_og_user_groups_form_submit($form, &$form_state) {
  if (is_array($form_state['values']['og_register']) && !empty($form_state['values']['account'])) {
    $og_register = $form_state['values']['og_register'];
    $account = $form_state['values']['account'];
    $dsm = FALSE;
    $active_groups = array_keys(array_filter($og_register));

    // Subscribe users to any selected groups.
    foreach (array_diff($active_groups, array_keys($account->og_groups)) as $gid) {
      $return = og_subscribe_user($gid, $account);
      if (!empty($return['message'])) {
        $dsm = TRUE;
        drupal_set_message($return['message']);
      }
    }

    // Remove users from any unselected groups.
    foreach (array_diff(array_keys($og_register), $active_groups) as $gid) {
      og_delete_subscription($gid, $account->uid);
    }
    if (!$dsm) {
      drupal_set_message(t('Your group membership settings were saved successfully.'));
    }
  }
}