function taxonomy_autocomplete in Drupal 6
Same name and namespace in other branches
- 4 modules/taxonomy.module \taxonomy_autocomplete()
- 5 modules/taxonomy/taxonomy.module \taxonomy_autocomplete()
- 7 modules/taxonomy/taxonomy.pages.inc \taxonomy_autocomplete()
Helper function for autocompletion
1 string reference to 'taxonomy_autocomplete'
- taxonomy_menu in modules/
taxonomy/ taxonomy.module - Implementation of hook_menu().
File
- modules/
taxonomy/ taxonomy.pages.inc, line 113 - Page callbacks for the taxonomy module.
Code
function taxonomy_autocomplete($vid, $string = '') {
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
$array = drupal_explode_tags($string);
// Fetch last tag
$last_string = trim(array_pop($array));
$matches = array();
if ($last_string != '') {
$result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
$prefix = count($array) ? implode(', ', $array) . ', ' : '';
while ($tag = db_fetch_object($result)) {
$n = $tag->name;
// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $tag->name) . '"';
}
$matches[$prefix . $n] = check_plain($tag->name);
}
}
drupal_json($matches);
}