You are here

function _acl_edit_form_after_build in ACL 6

Same name and namespace in other branches
  1. 8 acl.admin.inc \_acl_edit_form_after_build()
  2. 7 acl.admin.inc \_acl_edit_form_after_build()

Process a form that had our buttons on it.

1 string reference to '_acl_edit_form_after_build'
_acl_edit_form in ./acl.admin.inc
Implementation of acl_edit_form().

File

./acl.admin.inc, line 71
Implementations of administration functions for the acl module.

Code

function _acl_edit_form_after_build($form, $form_state) {

  // We can't use the form values because it's the entire structure
  // and we have no clue where our values actually are. That's
  // ok tho cause #value still works for us.
  $user_list = unserialize($form['user_list']['#value']);
  $button_name = 'acl_' . $form['acl_id']['#value'];
  if (isset($form['#post'][$button_name]) && $form['#post'][$button_name] == $form['delete_button']['#value']) {
    $deletions = $form['deletions']['#value'];
    foreach ($deletions as $uid) {
      unset($user_list[$uid]);
      unset($form['deletions']['#value'][$uid]);
    }
  }
  elseif (isset($form['#post'][$button_name]) && $form['#post'][$button_name] == $form['add_button']['#value']) {
    $user = db_fetch_object(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $form['add']['#value']));
    if (!$user || !$user->uid) {
      form_error($form['add'], t("Invalid user specified."));
    }
    else {
      $user_list[$user->uid] = $user->name;
      $form['add']['#value'] = NULL;
    }
  }
  if (count($user_list) != 0) {
    $form['deletions']['#type'] = 'checkboxes';
    $form['deletions']['#title'] = t("Current users");
    $form['deletions']['#options'] = $user_list;
    $form['deletions']['#value'] = array();

    // don't carry value through.
    $form['deletions'] = form_builder(!empty($form['#post']) ? $form['#post']['form_id'] : 'acl_form', $form['deletions'], $form_state);
  }
  else {
    $form['delete_button']['#type'] = 'value';
  }
  $form['user_list']['#value'] = serialize($user_list);
  return $form;
}