Full ELMS Learning Network documentation
function views_ajax_autocomplete_taxonomy
×
Error message
User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).cis7 ajax.inc | views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') |
cle7 ajax.inc | views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') |
elmsmedia7 ajax.inc | views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') |
icor7 ajax.inc | views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') |
meedjum_blog7 ajax.inc | views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') |
mooc7 ajax.inc | views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') |
Page callback for views taxonomy autocomplete.
Parameters
$vid: The vocabulary id of the tags which should be returned.
$tags_typed: The typed string of the user.
See also
Related topics
1 string reference to 'views_ajax_autocomplete_taxonomy'
- views_menu in sites/
all/ modules/ ulmus/ views/ views.module - Implement hook_menu().
File
- sites/
all/ modules/ ulmus/ views/ includes/ ajax.inc, line 332 - Handles the server side AJAX interactions of Views.
Code
function views_ajax_autocomplete_taxonomy($vid, $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 ($tag_last != '') {
$query = db_select('taxonomy_term_data', 't');
$query->addTag('translatable');
$query->addTag('term_access');
// Do not select already entered terms.
if (!empty($tags_typed)) {
$query->condition('t.name', $tags_typed, 'NOT IN');
}
// Select rows that match by term name.
$tags_return = $query->fields('t', array('tid', 'name'))->condition('t.vid', $vid)->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) . '"';
}
// Add term name to list of matches.
$term_matches[$prefix . $n] = check_plain($name);
}
}
drupal_json_output($term_matches);
}