function discussthis_autocomplete in Discuss This! 7.2
Same name and namespace in other branches
- 5 discussthis.module \discussthis_autocomplete()
- 6 discussthis.autocomplete.inc \discussthis_autocomplete()
- 7 discussthis.autocomplete.inc \discussthis_autocomplete()
Autocomplete a forum topic discussion title.
The function does not return if the auto-complete feature worked. Otherwise, it returns NULL.
NOTE : The previous version included a $tid parameter. It was not being used and it would not work properly if the user was creating a new node (i.e. you cannot select a forum, then a title, at least, not dynamically... and it was shown as being like that before.)
Parameters
$string The user string so far:
1 string reference to 'discussthis_autocomplete'
- discussthis_menu in ./
discussthis.module - Implements hook_menu().
File
- ./
discussthis.autocomplete.inc, line 24 - Function to compute the auto-complete string used in the discussion title.
Code
function discussthis_autocomplete($string = '') {
// Anything yet?
if (!$string) {
echo drupal_json_encode(array());
exit;
}
// Current user has the right to do that?!
if (!user_access('access content')) {
drupal_access_denied();
return;
}
$result = db_select('node', 'n')
->fields('n', array(
'nid',
'title',
))
->condition('type', 'forum', '=')
->condition('title', db_like($string) . '%', 'LIKE')
->execute();
$matches = array();
while ($record = $result
->fetchAssoc()) {
$matches[$record['nid']] = check_plain($record['title']) . ' [nid:' . $record['nid'] . ']';
}
echo drupal_json_encode($matches);
exit;
}