You are here

function spaces_user_autocomplete in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 spaces.admin.inc \spaces_user_autocomplete()
  2. 7 spaces.admin.inc \spaces_user_autocomplete()

Override of user/autocomplete. This accomplishes two things:

  • Pushes the result set through db_rewrite_sql() which allows access conditions to be placed on the query.
  • Uses a View, which allows implementing space types to filter the result set when a space is active.
1 string reference to 'spaces_user_autocomplete'
spaces_menu_alter in ./spaces.module
Implements hook_menu_alter().

File

./spaces.admin.inc, line 247

Code

function spaces_user_autocomplete($string = '') {
  $space = spaces_get_space();
  $matches = array();
  if ($string) {
    $query = db_select('users', 'u')
      ->fields('u', array(
      'name',
    ))
      ->condition('u.name', db_like($string) . '%', 'LIKE')
      ->range(0, 10)
      ->addTag('user_autocomplete');

    // Add spaces specific tag. Every Spaces Controller should implement
    // hook_query_spaces_user_autocomplet_[TYPE]_alter.
    // @see spaces_og_query_spaces_user_autocomplete_og_alter()
    if (isset($spaces->type)) {
      $query
        ->addTag('user_autocomplete_spaces');
      $query
        ->addTag('user_autocomplete_spaces_' . $spaces->type);
    }
    $result = $query
      ->execute();
    foreach ($result as $user) {
      $matches[$user->name] = check_plain($user->name);
    }
  }
  drupal_json_output($matches);
}