You are here

function og_role_watchdog_form_alter in Role Watchdog 6

Same name and namespace in other branches
  1. 6.2 modules/og_role_watchdog/og_role_watchdog.module \og_role_watchdog_form_alter()

Implementation of hook_form_alter

File

modules/og_role_watchdog/og_role_watchdog.module, line 93
Logs changes to user roles.

Code

function og_role_watchdog_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'og_user_roles_page_form') {
    $form['#submit'][] = 'og_role_watchdog_og_user_roles_submit';
    $original_user_roles = array();
    foreach ($form['user_roles'] as $uid => $info) {
      if (is_array($info) && array_key_exists('roles', $info)) {
        $old_roles = array();
        foreach ($info['roles']['#default_value'] as $old_role) {

          // $old_role may include the 'default role' for group admins.
          // Only include roles that have an entry in 'options' to avoid these.
          if (array_key_exists($old_role, $info['roles']['#options'])) {
            $old_roles[$old_role] = $old_role;
          }
        }
        $original_user_roles[$uid] = $old_roles;
      }
    }
    $form['original_user_roles'] = array(
      '#type' => 'value',
      '#value' => $original_user_roles,
    );
  }
}