According to the hook_entity_info documentation, a "label callback" can be used instead of the label property for providing the label of an entity. This project does not use the callback, causing a label to not be shown when only a callback is provided, as is the case in the Mailchimp contrib project.
Comments
Comment #2
slv_ commentedHi @derikson, thanks for opening this.
It looks like we should add support for this, indeed! I think I'll be able to pick it up later this week and get it on the next release. Thanks!
Comment #3
br0kenThe issue seems outdated to me, because everywhere in the module we're using the
entity_label()function to calculate the label of entity.Comment #4
derikson commentedThis is still a problem, because the
entityreference_autocomplete_resolve_entity_label_columnfunction assumes the text to search is in a label column, but instead it may be provided by a callback. The particular case where I ran into this problem, as an example, is with the MailChimp Signup module, where the entity does not even have a label column, instead relying on a callback to perform translations. In this case the search fails.Obviously any solution would have performance problems unless caching were added, since it would need to call the callback for every eligible entity on every search, but it should work for small sets of entities.
Comment #5
br0kenComment #6
slv_ commentedI'm unsure of what we can do here, but I'm open to suggestions if we can do something to get this feature added.
If there isn't a 'label' column for the entity type, the system will fall back to the 'id' column for searching, so an entity could be referenced by entering it's ID, and the actual label should be returned in the results for the user to select (as provided by the 'label callback' function).
Validation poses another problem, as not having anything to search against in the db, means we can mostly check just entity ID. Can see a few possible ways, but both involving either adding a new custom hook for this, and any case new logic to filter out returned entities after calling their 'label callback', to see if they should be returned as results or not.
Need to think a bit more about it, and see whether that'd fit a possible 2.x release instead of putting it in 1.x, as it means tinkering quite a bit in both the validation and autocomplete callbacks, but in any case, ideas welcome.
Comment #7
slv_ commentedHi,
I'm going to close this, just to avoid any expectations of it getting implemented. I'm not opposed to getting some support for it if someone decides to contribute it, but I don't plan to add it myself because:
1.- Seems a very extreme use case caused by a non-standard definition of entities from the mailchimp module (I might be wrong here, don't know enough details of the actual implementation in the mailchimp module).
2.- I don't think this module should go into adding complex logic with caching to allow searching in "virtual" fields created on the fly. A better solution would be to alter the entities created by mailchimp so that they have an actual label column to search on if you can't rely just on the entity ID.
Alternatively, Search API makes way more sense for your use case, so perhaps you could have a form element type to simply search in a search api index that already stores the label you need as an aggregated field. All the logic for aggregation and searching exists in that module already, and I don't see any reason to have something custom in this module.
Feel free to reopen. Thanks!
Comment #8
5n00py commentedI just implemented same functionality for eck entity in custom module, here is an example.