You are here

function acl_edit_form_after_build in ACL 5

Process a form that had our buttons on it.

1 string reference to 'acl_edit_form_after_build'
acl_edit_form in ./acl.module
Provide a form to edit the ACL that can be embedded in other forms. Pass $new_acl=TRUE if you have no ACL yet, but do supply a string like 'my_module_new_acl' as $acl_id anyway.

File

./acl.module, line 131
acl.module

Code

function acl_edit_form_after_build($form, $form_values) {

  // We can't use 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']);
  if ($form['delete_button']['#value'] && is_array($form['deletions']['#value'])) {
    foreach ($form['deletions']['#value'] as $uid) {
      unset($user_list[$uid]);
    }
  }
  else {
    if ($form['add_button']['#value']) {
      $name = $form['add']['#value'];
      $u = db_fetch_object(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $name));
      if (!$u->uid) {
        form_error($form['add'], "Invalid user.");
      }
      else {
        $user_list[$u->uid] = $u->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.
    // need $form_id and have no way to get it but from $_POST that
    // I can find; and if we got here that variable's already been
    // checked.
    $form['deletions'] = form_builder($_POST['form_id'], $form['deletions']);
  }
  else {
    $form['delete_button']['#type'] = 'value';
  }
  $form['user_list']['#value'] = serialize($user_list);
  return $form;
}