Projet

Général

Profil

Révision cfceb792

Ajouté par Assos Assos il y a plus de 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/acl/acl.admin.inc
5 5
 * Implementations of administration functions for the acl module.
6 6
 */
7 7

  
8
/**
9
 * Implementation of acl_get_usernames().
10
 */
11
function _acl_get_usernames($acl_id) {
12
  $users = array();
13
  $result = db_query("SELECT u.uid, u.name FROM {users} u LEFT JOIN {acl_user} aclu ON aclu.uid = u.uid WHERE acl_id = :acl_id", array(
14
    'acl_id' => $acl_id));
15
  foreach ($result as $user) {
16
    $users[$user->uid] = _acl_format_username($user);
17
  }
18
  return $users;
19
}
20

  
8 21
/**
9 22
 * Implementation of acl_edit_form().
10 23
 */
......
17 30
    ))->fetchAssoc())) {
18 31
      return array();
19 32
    }
20
    $result = db_query("SELECT u.uid, u.name FROM {users} u LEFT JOIN {acl_user} aclu ON aclu.uid = u.uid WHERE acl_id = :acl_id", array(
21
      'acl_id' => $acl_id));
22
    foreach ($result as $user) {
23
      $users[$user->uid] = $user->name;
24
    }
33
    $users = _acl_get_usernames($acl_id);
25 34
  }
26 35
  if (!isset($label)) {
27 36
    $label = (isset($record['name']) ? $record['name'] : (isset($record['number']) ? $record['number'] : $acl_id));
......
81 90
  // We can't use the form values because it's the entire structure
82 91
  // and we have no clue where our values actually are. That's
83 92
  // ok tho cause #value still works for us.
84
  $user_list = unserialize($form['user_list']['#value']);
85
  $button_name = 'acl_' . $form['acl_id']['#value'];
93
  $user_list = acl_edit_form_get_user_list($form);
86 94

  
87 95
  if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#value'] == $form['delete_button']['#value']) {
88 96
    $deletions = $form['deletions']['#value'];
......
99 107
      form_error($form['add'], t("Invalid user specified."));
100 108
    }
101 109
    else {
102
      $user_list[$user->uid] = $user->name;
110
      $user_list[$user->uid] = _acl_format_username($user);
103 111
      $form['add']['#value'] = NULL;
104 112
    }
105 113
  }
......
125 133
 * The module that embedded our form must call this function!
126 134
 */
127 135
function acl_save_form($form, $priority = NULL) {
128
  $users = unserialize($form['user_list']);
136
  $users = acl_edit_form_get_user_list($form);
129 137
  db_delete('acl_user')
130 138
    ->condition('acl_id', $form['acl_id'])
131 139
    ->execute();
......
147 155
  }
148 156
}
149 157

  
158
/**
159
 * Decode and return the list of users.
160
 *
161
 * @param array $form
162
 *   The ACL form or form_state array.
163
 * @param bool $get_default
164
 *   (optional) In the case of a form array, whether to return the
165
 *   '#default_value' (or the '#value').
166
 *
167
 * @return array
168
 *   An array of $uid => $username.
169
 */
170
function acl_edit_form_get_user_list($form, $get_default = FALSE) {
171
  if (is_array($form['user_list'])) {
172
    return unserialize($form['user_list'][$get_default ? '#default_value' : '#value']);
173
  }
174
  return unserialize($form['user_list']);
175
}
176

  

Formats disponibles : Unified diff