You are here

function term_permissions_autocomplete_multiple in Taxonomy Term Permissions 7

Same name and namespace in other branches
  1. 6 term_permissions.module \term_permissions_autocomplete_multiple()

Returns Json array for Taxonomy Term Permissions autocomplete fields. Supports multiple entries separated by a comma.

1 string reference to 'term_permissions_autocomplete_multiple'
term_permissions_menu in ./term_permissions.module
Implements hook_menu().

File

./term_permissions.module, line 320
Allows access to terms in a vocabulary to be limited by user or role.

Code

function term_permissions_autocomplete_multiple($string) {

  // The user enters a comma-separated list of users.
  // We only autocomplete the last user.
  $array = drupal_explode_tags($string);

  // Fetch last user.
  $last_string = trim(array_pop($array));
  $matches = array();
  $result = db_select('users')
    ->fields('users', array(
    'name',
  ))
    ->condition('name', db_like($last_string) . '%', 'LIKE')
    ->range(0, 10)
    ->execute();
  $prefix = count($array) ? implode(', ', $array) . ', ' : '';
  foreach ($result as $user) {
    $matches[$prefix . $user->name] = check_plain($user->name);
  }
  exit(drupal_json_output($matches));
}