function _i18n_taxonomy_autocomplete in Internationalization 7
Helper function for autocompletion
2 calls to _i18n_taxonomy_autocomplete()
- i18n_taxonomy_autocomplete_field in i18n_taxonomy/
i18n_taxonomy.pages.inc - Helper function for autocompletion. Replacement for taxonomy_autocomplete
- i18n_taxonomy_autocomplete_language in i18n_taxonomy/
i18n_taxonomy.pages.inc - Helper function for autocompletion. Select by language
File
- i18n_taxonomy/
i18n_taxonomy.pages.inc, line 93 - Page callbacks for the taxonomy module, i18n remake.
Code
function _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed = '') {
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
$tags_typed = drupal_explode_tags($tags_typed);
$tag_last = drupal_strtolower(array_pop($tags_typed));
$matches = array();
if ($langcode && $tag_last != '') {
$query = db_select('taxonomy_term_data', 't')
->fields('t', array(
'tid',
'name',
));
$query
->addTag('translatable');
$query
->addTag('taxonomy_term_access');
// Disable i18n_select for this query
$query
->addTag('i18n_select');
// Add language condition
$query
->condition('t.language', $langcode);
// Do not select already entered terms.
if (!empty($tags_typed)) {
$query
->condition('t.name', $tags_typed, 'NOT IN');
}
// There may be vocabulary restrictions
if ($vids) {
$query
->condition('t.vid', $vids);
}
// Select rows that match by term name.
$tags_return = $query
->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
->range(0, 10)
->execute()
->fetchAllKeyed();
$prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
$term_matches = array();
foreach ($tags_return as $tid => $name) {
$n = $name;
// Term names containing commas or quotes must be wrapped in quotes.
if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $name) . '"';
}
$term_matches[$prefix . $n] = check_plain($name);
}
}
drupal_json_output($term_matches);
}