You are here

function _acl_edit_form_after_build in ACL 7

Same name and namespace in other branches
  1. 8 acl.admin.inc \_acl_edit_form_after_build()
  2. 6 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 89
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 = acl_edit_form_get_user_list($form);
  if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#value'] == $form['delete_button']['#value']) {
    $deletions = $form['deletions']['#value'];
    foreach ($deletions as $uid) {
      unset($user_list[$uid]);
      unset($form['deletions']['#value'][$uid]);
    }
  }
  elseif (isset($form_state['triggering_element']) && $form_state['triggering_element']['#value'] == $form['add_button']['#value'] && !empty($form['add']['#value'])) {
    $user = db_query("SELECT uid, name FROM {users} WHERE name = :name", array(
      'name' => $form['add']['#value'],
    ))
      ->fetchObject();
    if (!$user) {
      form_error($form['add'], t("Invalid user specified."));
    }
    else {
      $user_list[$user->uid] = _acl_format_username($user);
      $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;
}