finder_autocomplete_autocomplete

  1. finder
    1. 6.x-1.x
    2. 7.x-1.x
Versions
6.x-1.x – 7.x-1.x finder_autocomplete_autocomplete($finder_id, $finder_element_id, $keywords = '')

Menu callback; get autocomplete suggestions.

Code

modules/finder_autocomplete/finder_autocomplete.module, line 165

<?php
function finder_autocomplete_autocomplete($finder_id, $finder_element_id, $keywords = '') {

  $choices = array();

  if ($keywords === '') {
    drupal_json($choices);
  }

  $finder = finder_load($finder_id);
  $element = &finder_element($finder, $finder_element_id);
  $fields = &$element->settings['choices']['field'];
  foreach ($fields as $key => $field) {
    $field_info[$key] = finder_split_field($field);
    $field_names[$key] = $field_info[$key]['field'];
  }

  $pager = &$element->settings['form']['max_suggestions'];
  $match = $element->settings['form']['match'] ? $element->settings['form']['match'] : 'c';

  if (!empty($element->settings['form']['delimit_autocomplete'])) {
    $keywords = array($keywords);
    foreach ($keywords as $k => $v) {
      unset($keywords[$k]);
      $exploded = explode($element->settings['form']['delimit_autocomplete'], $v);
      foreach ($exploded as $e) {
        $keywords[] = trim($e);
      }
    }
  }

  $options = finder_find($finder, array($finder_element_id => $keywords), 'choices', $match, $pager);

  if ($options) {
    foreach ($options as $option) {
      $autofill = theme('finder_autocomplete_autofill', array('option' => $option, 'finder_element' => $element));
      $suggestion = theme('finder_autocomplete_suggestion', array('option' => $option, 'finder_element' => $element));
      if ($autofill && $suggestion) {
        $choices[$autofill] = $suggestion;
      }
    }
  }

  drupal_json_output($choices);

}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.