function fontyourface_ui_autocomplete in @font-your-face 7.2
Returns JSON-encoded autocomplete matches.
1 string reference to 'fontyourface_ui_autocomplete'
- fontyourface_ui_menu in modules/
fontyourface_ui/ fontyourface_ui.module - Implements hook_menu().
File
- modules/
fontyourface_ui/ fontyourface_ui.module, line 1284
Code
function fontyourface_ui_autocomplete($tags_typed = '') {
$tags_typed = drupal_explode_tags($tags_typed);
$tag_last = drupal_strtolower(array_pop($tags_typed));
$matches = array();
if ($tag_last != '') {
$query = db_select('fontyourface_tag', 't');
// Do not select already entered tags.
if (!empty($tags_typed)) {
$query
->condition('t.name', $tags_typed, 'NOT IN');
}
// if
// Select rows that match by tag name.
$tags_return = $query
->fields('t', array(
'tid',
'name',
))
->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
->range(0, 10)
->execute()
->fetchAllKeyed();
$prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : '';
$matches = array();
foreach ($tags_return as $tid => $name) {
$n = $name;
// Tag names containing commas or quotes must be wrapped in quotes.
if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $name) . '"';
}
else {
$matches[$prefix . $n] = check_plain($name);
}
// else
}
// foreach
}
// if
drupal_json_output($matches);
}