This is especially important together with the "show all" functionality.
The node references module has the limit currently hardcoded to 10, so I had to supply a different autocomplete callback, where I did set it manually to 200. This should probably be configurable.
Here is the code, mostly copy & paste from the node references module:
/**
* Implements hook_menu().
*/
function acdx_node_reference_menu() {
$items['acdx_node_reference/autocomplete/%/%/%'] = array(
'page callback' => 'acdx_node_reference_autocomplete',
'page arguments' => array(2, 3, 4),
'access callback' => 'reference_autocomplete_access',
'access arguments' => array(2, 3, 4),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Menu callback for the autocomplete results.
*/
function acdx_node_reference_autocomplete($entity_type, $bundle, $field_name, $string = '') {
$field = field_info_field($field_name);
$instance = field_info_instance($entity_type, $field_name, $bundle);
$options = array(
'string' => $string,
'match' => $instance['widget']['settings']['autocomplete_match'],
'limit' => 200,
);
$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);
}
function acdx_node_reference_field_widget_info() {
return array(
'node_reference_autocomplete_deluxe' => array(
'label' => t('Autocomplete Deluxe'),
'description' => t('Display the list of referenceable nodes as a textfield with autocomplete deluxe behaviour.'),
'field types' => array('node_reference'),
'settings' => array(
'autocomplete_match' => 'contains',
'size' => 60,
'autocomplete_path' => 'acdx_node_reference/autocomplete',
),
),
);
}
Comments
Comment #1
berdirNow again, better formatted:
If you need, I can make a patch of this, but it's all new code except the widget info hook where I just changed the autocomplete path.
Note that I had to re-save the settings form after changing the path of existing fields to update the settings.
Comment #2
spacereactor commentedIf there is a UI for changing the display limit will be easier to work with
Comment #3
marcoscanosubscribe, would love to have it in the UI also
Comment #4
sepgil commentedIf you could provide a patch, I would be glad to commit it.
Comment #5
zatarain21 commentedI agree
Comment #6
drclaw commentedThought I'd take a stab at this one. This should do the trick. Let me know if it works for you all!
Comment #7
drclaw commentedThat last one had a little mistake with the element default value. This one is better. Sorry about that!
Comment #7.0
chop commentedFix PHP open / close tags to allow correct code formatting