function node_reference_autocomplete in References 7.2
Menu callback for the autocomplete results.
5 string references to 'node_reference_autocomplete'
- NodeReferenceFormTest::testLongNodeReferenceWidget in node_reference/
node_reference.test - Test autocomplete widget.
- node_reference_content_migrate_instance_alter in node_reference/
node_reference.module - Implements hook_content_migrate_instance_alter().
- node_reference_field_widget_form in node_reference/
node_reference.module - Implements hook_field_widget_form().
- node_reference_field_widget_settings_form in node_reference/
node_reference.module - Implements hook_field_widget_settings_form().
- node_reference_menu in node_reference/
node_reference.module - Implements hook_menu().
File
- node_reference/
node_reference.module, line 983 - Defines a field type for referencing one node from another.
Code
function node_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 = node_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']);
// Add a class wrapper for a few required CSS overrides.
$matches[$row['title'] . " [nid:{$id}]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
}
drupal_json_output($matches);
}