Page callback for views tag autocomplete
function views_ui_autocomplete_tag($string = NULL) {
$matches = array();
if (!isset($string)) {
$string = drupal_container()
->get('request')->query
->get('q');
}
// get matches from default views:
$views = views_get_all_views();
foreach ($views as $view) {
$tag = $view
->get('tag');
if ($tag && strpos($tag, $string) === 0) {
$matches[$tag] = $tag;
if (count($matches) >= 10) {
break;
}
}
}
return new JsonResponse($matches);
}