You are here

function profile_autocomplete in Drupal 7

Same name and namespace in other branches
  1. 5 modules/profile/profile.module \profile_autocomplete()
  2. 6 modules/profile/profile.pages.inc \profile_autocomplete()

Callback to allow autocomplete of profile text fields.

1 string reference to 'profile_autocomplete'
profile_menu in modules/profile/profile.module
Implements hook_menu().

File

modules/profile/profile.pages.inc, line 118
User page callbacks for the profile module.

Code

function profile_autocomplete($field, $string) {
  $matches = array();
  $autocomplete_field = (bool) db_query_range("SELECT 1 FROM {profile_field} WHERE fid = :fid AND autocomplete = 1", 0, 1, array(
    ':fid' => $field,
  ))
    ->fetchField();
  if ($autocomplete_field) {
    $values = db_select('profile_value')
      ->fields('profile_value', array(
      'value',
    ))
      ->condition('fid', $field)
      ->condition('value', db_like($string) . '%', 'LIKE')
      ->groupBy('value')
      ->orderBy('value')
      ->range(0, 10)
      ->execute()
      ->fetchCol();
    foreach ($values as $value) {
      $matches[$value] = check_plain($value);
    }
  }
  drupal_json_output($matches);
}