You are here

function permissions_by_term_autocomplete_multiple in Permissions by Term 7

Page callback: Returns Json array for autocomplete fields.

Supports multiple entries separated by a comma.

Parameters

string $string: A comma-separated list of users.

1 string reference to 'permissions_by_term_autocomplete_multiple'
permissions_by_term_menu in ./permissions_by_term.module
Implements hook_menu().

File

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

Code

function permissions_by_term_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);
  }
  drupal_json_output($matches);
}