You are here

function linkit_autocomplete in Linkit 7

Same name and namespace in other branches
  1. 6 linkit.module \linkit_autocomplete()
  2. 7.3 linkit.module \linkit_autocomplete()

Autocomplete callback function.

1 string reference to 'linkit_autocomplete'
linkit_menu in ./linkit.module
Implements hook_menu().

File

./linkit.module, line 187
Main file for linkit module.

Code

function linkit_autocomplete($string = NULL) {
  $matches = array();
  $hook_matches = array();
  if ($string) {
    $hook_matches = module_invoke_all('linkit_load_plugins', $string);
    foreach ($hook_matches as $module => $values) {
      if (module_exists('linkit_permissions')) {
        if (user_access('use linkit ' . $module . ' plugin') || user_access('use all linkit plugins')) {
          $matches = array_merge($matches, $hook_matches[$module]);
        }
      }
      else {
        $matches = array_merge($matches, $hook_matches[$module]);
      }
    }
  }

  // hook_linkit_load_plugins_alter() , let other modules change the matches array
  drupal_alter('linkit_load_plugins', $matches);
  $results = array();
  foreach ($matches as $match) {

    // Build the val
    $val = check_plain($match['title'] . ' [path:' . $match['path'] . ']');

    // Get the extra information text
    $information = array();
    foreach ($match['information'] as $extra_info_key => $extra_info_val) {

      // Coder is telling us that "The first parameter to t() should be a literal string. There should be no variables, concatenation, constants or other non-literal strings there"
      // But the "$extra_info_key" is hard coded and cant be change by users or administratios so its ok to use t() this way.
      $information[] = t(drupal_ucfirst($extra_info_key)) . ':<span>' . $extra_info_val . '</span>';
    }

    // Build the text
    $text = '<div class="clearfix">';
    $text .= '<div class="auto-item-title">' . check_plain($match['title']) . '</div>';
    if (count($information)) {
      $text .= '<div class="auto-item-info">[' . implode(", ", $information) . ']</div>';
    }
    $text .= '</div>';
    $results[$val] = $text;
  }
  drupal_json_output($results);
}