You are here

function user_reference_autocomplete in References 7.2

Menu callback.

Retrieve a pipe delimited string of autocomplete suggestions for existing users.

5 string references to 'user_reference_autocomplete'
user_reference_content_migrate_instance_alter in user_reference/user_reference.module
Implements hook_content_migrate_instance_alter().
user_reference_field_info in user_reference/user_reference.module
Implements hook_field_info().
user_reference_field_widget_form in user_reference/user_reference.module
Implements hook_field_widget_form().
user_reference_field_widget_settings_form in user_reference/user_reference.module
Implements hook_field_widget_settings_form().
user_reference_menu in user_reference/user_reference.module
Implements hook_menu().

File

user_reference/user_reference.module, line 975
Defines a field type for referencing a user from a node.

Code

function user_reference_autocomplete($entity_type, $bundle, $field_name, $string = '') {
  $instance = field_info_instance($entity_type, $field_name, $bundle);
  $field = field_info_field($field_name);
  $options = array(
    'string' => $string,
    'match' => $instance['widget']['settings']['autocomplete_match'],
    'limit' => $instance['widget']['settings']['limit'],
  );
  $references = user_reference_potential_references($field, $options);
  $matches = array();
  foreach ($references as $id => $row) {

    // Markup is fine in autocompletion results (might happen when rendered
    // through Views) but we want to remove hyperlinks.
    $suggestion = preg_replace('/<a href="([^<]*)">([^<]*)<\\/a>/', '$2', $row['rendered']);

    // Remove link tags Add a class wrapper for a few required CSS overrides.
    $matches[$row['title'] . " [uid:{$id}]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
  }
  drupal_json_output($matches);
}