Hi,
I'm using DATA to connect some drupal node to a row of a table created with data. Using drupal 6 I have a ckk field called "Data Record Reference" and using thid field I can use an autocomplete widget to select the row by a view. Everything is working correctly. I have a "user select field" to chose wich colum use for the selection into the widget and the "referencies Field to select the field used as identifier.
Now I'm try to repeated the same operation usinf drupal 7 but there isn't the "Data Record Reference", I have try using Entity Reference but in this case the widget to select the row is empty and I don't have the possibility to chose "selection" and "identifier". Someone have an idea to replace the same condition into drupal 7?
Comment | File | Size | Author |
---|---|---|---|
#25 | 1538588.25.data_.entity-label-field.patch | 2.53 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedSelecting a data item from somewhere else with entity reference probably won't work yet. The main thing is probably the absence of a label callback...
Comment #2
imclean CreditAttribution: imclean commentedSee #1551430: implement hook_entity_property_info for Feeds integration
I've added a label to hook_entity_property_info() which may help.
Comment #3
joachim CreditAttribution: joachim commentedI suspect it's rather the label callback in hook_entity_info() that we need, but that would need checking.
Comment #4
joachim CreditAttribution: joachim commentedYup, it uses entity_label(): http://api.drupal.org/api/drupal/includes!common.inc/function/entity_lab...
Hence we need a label key or callback.
Comment #5
imclean CreditAttribution: imclean commentedThank joachim. Feeds integration is something I'm keen to get working and I've noticed data_entity lacks a few required methods and properties. The label shouldn't be too hard to add.
Comment #6
imclean CreditAttribution: imclean commentedLooking at entity_data.module's hook_entity_info(), the label is currently set to the table's title. ['entity keys']['label'] is not set.
Comment #7
joachim CreditAttribution: joachim commentedThose are two different things.
$info[label] is the label of the entities as a whole, like 'Node'.
$info['entity keys']['label'] is the key on the entity that gives you the label for that entity, so like 'About us' for a page node.
Comment #8
imclean CreditAttribution: imclean commentedIn the case of a data entity, I imagine $info['entity keys']['label'] would the primary key(s). Except the primary key field is used as the entity ID, which needs to be an integer, so that wouldn't be very friendly. This could be combined with the table name or label.
This may be a rare case: my primary key field is an auto-increment integer field which isn't included when saving the entity.
Ideally, the primary key(s) could be independent of the entity ID, with a separate config option to specify the entity ID field.
Comment #9
imclean CreditAttribution: imclean commentedAlternatively, data_entity could set and increment the ID specific to each entity type.
Comment #10
imclean CreditAttribution: imclean commentedOk, to the topic at hand: could the label be 1 or more fields selected on the "Configure Entity Form"? Does it need to be unique?
Comment #11
imclean CreditAttribution: imclean commentedAdded a label callback which uses index fields as the label. Multiple indexes are separated by a space in the label.
Comment #12
imclean CreditAttribution: imclean commentedUpdated status.
Comment #13
joachim CreditAttribution: joachim commentedThis will return NULL if there aren't any indexes, which may cause problems with other modules expecting a string.
Should we return something like '' or 'No label'?
Alternatively, we could add checkboxes to the data table management UI to pick which columns to make up labels.
Comment #14
imclean CreditAttribution: imclean commented"No label" sounds good.
This adds the option to the Entity Configuration form.
Some notes:
1. The schema is used to get the fields in their correct order. This may be important for label fields but if it isn't we could just loop through the meta information.
2. The callback looks a bit clumsy getting all the information. There may be a cleaner way.
3. Unrelated to this issue: theme_data_entity_admin_entity_form() sticks an extra blank cell at the end of each row. Is this necessary?
Comment #15
joachim CreditAttribution: joachim commentedI don't think you need to get the schema here. Just iterate over $meta['fields'] and see if there are labels set.
Alternatively, perhaps in the submit handler for data_entity_admin_entity_form() we could save a nice piece of metadata that specifically gives us a list of the label fields, so we don't need to muck about with looping every time.
Also, does DataTable::instance() cache anything? If not, we should possibly investigate performance of this, say in an entity reference field.
Finally, I've just thought of something -- how does the autocomplete widget for entref work? Is it compatible with a label callback that builds the label programmatically, or does it only work with a particular entity property being the label? If that's the case, we should probably limit just one column to being the label.
Comment #16
imclean CreditAttribution: imclean commentedThe schema reflects the order of the fields in the admin screens, $meta['fields'] doesn't. That said, a list of label fields as separate metadata sounds like a nicer way to go.
I'm not sure about autocomplete, I'll have to check.
What alternatives are there to DataTable::instance()? All we really need is the metadata, can Data module provide this alone?
Comment #17
joachim CreditAttribution: joachim commented> What alternatives are there to DataTable::instance()? All we really need is the metadata, can Data module provide this alone?
Oh I'm fairly sure we need this, as it's the way into the Data API. My concern is that if you're looking at a dropdown of entities, creating that class and having it load the same thing from the database once for each entity in the dropdown is going to be quite expensive. I'd like that to be statically cached somewhere.
Comment #18
imclean CreditAttribution: imclean commentedMultiple label fields may be overkill. If we only had one we could potentially avoid a label callback, although we'd need a helper function for hook_entity_info(). Does this cache its information?
Comment #19
joachim CreditAttribution: joachim commentedYup, hook_entity_info() is cached. Doing expensive things in that is fine, though beware of circularity there.
Comment #20
imclean CreditAttribution: imclean commentedHere's a much simpler approach which allows one column to be selected as the label. If one isn't specified a callback is used so it doesn't break anything.
Comment #21
joachim CreditAttribution: joachim commentedLooks good. Would be great if someone could try it out!
Comment #22
imclean CreditAttribution: imclean commentedUpdated title. Hopefully we can get some action here.
Comment #23
Cayenne CreditAttribution: Cayenne commentedBeen struggling with this all day. Hoped that the patch would cure it. Still not able to display anything at all for the referenced data. Is anybody able to make this work, or is it just me?
Comment #24
imclean CreditAttribution: imclean commentedHard to know. This patch does add the entity label as described, but there may be other issues.
What modules and what patches are you using?
Comment #25
joachim CreditAttribution: joachim commentedThe patch at #20 was nearly there -- just wasn't saving the setting in the UI.
Here's an update patch.
Comment #26
joachim CreditAttribution: joachim commentedCommitted. New alpha release shortly!
Thanks to everyone who's worked on this.
SHA: 9865f0c0ca4c70701fe8a9d977f535beedfcb53c
Author: imclean
Subject: Issue #1538588 by imclean, joachim: Added setting for field to use for entity label, thus allowing use of data entities as targets for entityreference fields.