public function drupalchatController::_drupalchat_ur_autocomplete in DrupalChat 8
Implements autocomplete feature for UR Integration.
1 string reference to 'drupalchatController::_drupalchat_ur_autocomplete'
File
- src/
Controller/ drupalchatController.php, line 1140 - Contains Drupal\drupalchat\Controller\drupalchatController
Class
Namespace
Drupal\drupalchat\ControllerCode
public function _drupalchat_ur_autocomplete($string) {
$array = Tags::explode($string);
// Fetch last value
$last_string = Unicode::strtolower(array_pop($array));
$matches = array();
$query = db_select('user_relationship_types', 'u');
// Select rows that match the string
$return = $query
->fields('u', array(
'name',
))
->condition('u.name', '%' . db_like($last_string) . '%', 'LIKE')
->range(0, 10)
->execute();
$prefix = count($array) ? Tags::implode($array) . ', ' : '';
// add matches to $matches
foreach ($return as $row) {
if (!in_array($row->name, $array)) {
$matches[$prefix . $row->name] = Html::escape($row->name);
}
}
// return for JS
return new JsonResponse($matches);
}