hi,
I ve coded an autocomplete widget on top of Search API and i ve found a little bug :
line 453 of node_reference.module should be :
'#autocomplete_path' => $instance['widget']['settings']['autocomplete_path'] . '/' . $instance['bundle'] . '/' . $field['field_name'],
and so line 677 your @todo broken could be fixed
// $entity_type => $bundle
function node_reference_autocomplete($bundle, $field_name, $string = '') {
//$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $bundle);
// @todo broken - this is in $instance['widget']['settings']['autocomplete_match'] - we'd need the $instance.
maybe you already knew it... was just trying to help !
PS :
what do you think about :
http://drupal.org/project/relation
Comments
Comment #1
danielb commentedA few questions, if I may ask.
- Does changing the $entity_type variable to $bundle have any other implications? $entity_type is used in other functions, should those be renamed to $bundle? Or was the name $entity_type used incorrectly in only node_reference_autocomplete()?
- It appears $field is still required to be passed to _node_reference_potential_references(). I notice you've commented $field out in yours - can you explain?
- Does the @todo, and the changes to the node_reference_autocomplete() function also apply to the user_reference module?
I think if these can be addressed, a patch could be made.
Comment #2
quazardous commented- Does changing the $entity_type variable to $bundle have any other implications? $entity_type is used in other functions, should those be renamed to $bundle? Or was the name $entity_type used incorrectly in only node_reference_autocomplete()?
>>> I think it s incorrect to use entity because fields are attached to bundle
- It appears $field is still required to be passed to _node_reference_potential_references(). I notice you've commented $field out in yours - can you explain?
>>> I rename $field in $instance for consistancy (instance is the "good" name) and it must be rename everywhere
- Does the @todo, and the changes to the node_reference_autocomplete() function also apply to the user_reference module?
>>> sry didn't pay attention to user_reference... but I think there is no different bundles for user entity. so the probleme is less important.
Comment #3
andypost@quazardous Can you provide a patch?
I think that using bundle is preferable. Field or Instance - this depends of context, if we talk about field that attached to bundle so we should use Instance
Comment #4
quazardous commentedi'll try to provide a patch but last weeks of the year are hard :p
Comment #5
fgmWe cannot just replace $field with $instance everywhere:
_node_reference_potential_references_standard(), invoked by_node_reference_potential_references()fromnode_reference_autocomplete(), makes use of$field['settings']['referenceable_types']: referenceable types are currently a per-field choice, not per-instance. It needn't remain so indefinitely, but this is a wider change.Patch rolled from the original suggestion, nothing bigger.
Also, for the record, user_reference assumes a single bundle on the user entity, and does not make use of the instance to differentiate per-bundle widgets properties since there is only one.
Comment #6
andypostUser autocomplete is totally broken now.
Patch fixes following:
- Fixes UID using more conditional logic
- Fixes arguments for filters: array_keys(array_filter($settings)) leaves only checked values for queries
- Used format_username() to allow modules a-la realname to alter user names?
Last one probably useless for this function so maybe it's different issue
Questions raised:
- Defaults for filters:
-- should we display autocomplete widget if nothing is checked in filters?
-- should we display Anonymous user? Currently using "%" as autocomplete value we could get Anonym into list
Comment #7
andypostFirst condition should be '&&' so if both settings empty
Added filter for anonymous user
Comment #8
andypostSorry, my last 2 comments are related to #1004212: [release blocker] Add content crashes with User reference field
#5 seems reasonable but I think settings (referenceable types) should be stored per instance but this different issue
Comment #9
fgmSee #1004212: [release blocker] Add content crashes with User reference field.
Comment #10
fgmDuplicate was obviously only for andypost's patch. I just rerolled the patch in #5 on today's version, but it needs
- to be reviewed
- a simpletest failing before the patch and passing after the patch
Comment #11
andypostPatch #5 works fine for a long time on one of my sites also this change is required
Possible test case: attach fields to different node types with different field settings and try to get right values from autocomplete. But I've no idea how to test results from autocomplete field because core's simpletest does not allow testing of JS
So it seems more reasonable to commit #5 without test coverage
Comment #13
johnv#5: references_993394.patch queued for re-testing.
Comment #14
calte commentedCan anyone confirm that http://drupal.org/node/1053288 is related?
Comment #15
yched commentedSorry for letting this slip by.
If we want to get the $instance, we need all three of [entity type, bundle, field name].
Attached patch seems to fix the thing for me - also I can't say that I really noticed any issue myself regarding autocomplete (apart from the 'starts with' / 'contains' widget setting which didn't work so far because we didn't get the instance).
I'd welcome a confirmation from the folks that had troubles with autocomplete. @andypost ?
Comment #16
dave reidRe-rolled against current 7.x-2.x-git. Also abstracted the access callback out since it could be used for both node and user references.
Comment #17
yched commented@Dave Reid : thks for the reroll, and good call about the access callback.
Committed roughly #16 (user_reference_autocomplete() still had the old signature). Thanks all !