You are here

function webform_references_node_autocomplete in Webform References 7

Menu callback for the autocomplete results.

1 string reference to 'webform_references_node_autocomplete'
webform_references_menu in ./webform_references.module
Implements hook_menu().

File

./webform_references.node.inc, line 577
Webform module node reference component.

Code

function webform_references_node_autocomplete($bundles, $string = '') {
  $options = array(
    'string' => $string,
    'limit' => 10,
  );
  $references = webform_references_node_potential_references($bundles, $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']);

    // Add a class wrapper for a few required CSS overrides.
    $matches[$row['title'] . " [id:{$id}]"] = check_plain($suggestion);
  }
  drupal_json_output($matches);
}