function notifications_tags_autocomplete in Notifications 6.4
Same name and namespace in other branches
- 6 notifications_tags/notifications_tags.module \notifications_tags_autocomplete()
- 6.2 notifications_tags/notifications_tags.module \notifications_tags_autocomplete()
- 6.3 notifications_tags/notifications_tags.module \notifications_tags_autocomplete()
- 7 notifications_tags/notifications_tags.module \notifications_tags_autocomplete()
Helper function for term name autocompletion
It is similar to taxonomy_autocomplete but:
- Just searches terms in allowed vocabularies
- Has single/multiple switch in the path
Parameters
$type: 'single' or 'multiple'
1 string reference to 'notifications_tags_autocomplete'
- notifications_tags_menu in notifications_tags/
notifications_tags.module - Implementation of hook_menu_()
File
- notifications_tags/
notifications_tags.module, line 321 - Subscriptions to taxonomy terms
Code
function notifications_tags_autocomplete($type, $string = '') {
$matches = array();
if ($vocabs = notifications_tags_vocabularies()) {
// If multiple, the user enters a comma-separated list of tags. We only autocomplete the last tag.
if ($type == 'multiple') {
$array = drupal_explode_tags($string);
}
else {
$array = array(
$string,
);
}
// Fetch last tag
$last_string = trim(array_pop($array));
if ($last_string != '') {
// Add vids and name to args
$args = array_keys($vocabs);
$args[] = $last_string;
$result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid IN (" . db_placeholders($vocabs) . ") AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $args, 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);
}