You are here

function token_autocomplete_type in Token 7

1 call to token_autocomplete_type()
token_autocomplete in ./token.pages.inc

File

./token.pages.inc, line 318
User page callbacks for the token module.

Code

function token_autocomplete_type($string = '') {
  $token_info = token_info();
  $types = $token_info['types'];
  $matches = array();
  foreach ($types as $type => $info) {
    if (!$string || strpos($type, $string) === 0) {
      $type_key = "[{$type}:";
      $matches[$type_key] = levenshtein($type, $string);
    }
  }
  if ($string) {
    asort($matches);
  }
  else {
    ksort($matches);
  }
  $matches = drupal_map_assoc(array_keys($matches));
  drupal_json_output($matches);
}