Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi!
I have a field collection called "Copies", which contains different fields, like a "Name". I have a content type, with a field of type Entity Reference. As target type I select Field Collection Item. The problem is that when I add a content of this type, when I insert the field that references the field collection, I see they are all called "Copies 1", "Copies 2", "Copies 3", etc... but I want their "Name" to be shown instead. Is it possible? How can I do it?
Thank you in advanced for your help! :)
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedI have same problem and no solution :-(
Comment #2
RobW CreditAttribution: RobW commentedTechnically, the titles of the entities you're referencing are [field collection name] [delta]. If you want to show one of the collected fields as the "title" you'll need to do some custom theming. I suggest using entity_metadata_wrapper() to get collected field values out of the collection.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks RobW. I will try it.
Comment #4
annieliu CreditAttribution: annieliu commentedHi, does anyone have any progress on this? I'm new to drupal and would like to do exactly the same thing for my website. Thanks!
Comment #5
johnhanley CreditAttribution: johnhanley commentedI likewise have a entity reference of a field collection and need to display the values of one of the fields instead of [field collection name] [delta].
Here's an example. I have 2 content types:
Group
Project
Group includes a field collection called Member consisting of 3 fields:
Full name
Telephone
Email address
Project includes a entity reference select list of field collection Member.
The labels of the select list use [field collection name] [delta], which is completely unintuitive.
For example:
Member 1
Member 2
instead of
Mickey Mouse
Donald Duck
Using my example how can the labels of the select list be replaced with "Full name"?
Comment #6
RobW CreditAttribution: RobW commentedFor deeper integration like entity fields you'll need a submodule that can revise the title of the field collection item entity. Probably a good case for a new related module. Some ways it could be done:
Better, but more complex:
You'd need to make sure that the FC module never expects the current title structure for any logic, which I believe it doesn't. There might be some sticky race conditions here too, if creating the entity happens before saving fields, but not sure how that works off the top of my head.
Thinking out loud here, might revisit when I have some spare time.
Comment #7
RobW CreditAttribution: RobW commentedComment #8
johnhanley CreditAttribution: johnhanley commentedHi Rob,
Thanks for your quick and detailed response.
I like both of your suggestions. I have in fact already started creating a module to do the former, but it's certainly not as elegant or versatile as the latter.
I'll follow-up in this thread when there's something to report.
Regards,
John
Comment #9
RobW CreditAttribution: RobW commentedIf anyone decides to try the 2nd method, looking at the code in Automatic Nodetitles would be a good place to start. As a bonus, it was written by Fago, so the coding style may be similar to Field Collection.
[Edit] You might want to try Automatic Entity Labels. If it works with field collections it will solve the original poster's issue.
Comment #10
annieliu CreditAttribution: annieliu commentedUnfortunately Automatic Entity Labels doesn't seem to work with field collections. Would very much like to hear from Bacteria Man on the progress. Thanks.
Comment #11
drupalok CreditAttribution: drupalok commentedUnfortunately bacteria man opted out of this, i guess
http://drupal.org/node/1672718#comment-6527292
Comment #12
johnhanley CreditAttribution: johnhanley commentedHey guys,
I haven't decided for sure, but I believe my direction will be to use Entity Reference instead of References. This means using Field reference is out.
I'm also exploring the use of Relation (which sounds awesome), but I need more time to experiment.
I have a couple of other priorities that need my immediate attention, but I will follow-up in this thread as soon as possible.
Thanks,
John (aka. Bacteria Man)
Comment #13
archnode CreditAttribution: archnode commentedI don't think that a field collection item
hasshould have an explicit title/label. Why don't you just add a title field to the field collection and create a view with an entity_reference display in which you use the newly added title field instead of the id?Then you can switch the entity selection mode from "simple" to "views" and select your entity display and you got your select field with title.
Comment #14
drupalok CreditAttribution: drupalok commented*EDIT * that was rubbish
i will try again...
Comment #15
RobW CreditAttribution: RobW commentedThe reason Auto Entity Titles doesn't work with Field Collection is that FC doesn't have a label field. I think the easiest and most future compatible fix for this issue is to patch the module to include a non-user configurable label that's filled by default with the current pattern and then use Auto Entity Title to configure it. I might try to code that up this weekend.
Comment #16
drupalok CreditAttribution: drupalok commented@ RobW
this would be awesome, thanks! i tried archnodes suggestion by adding a reference view for the entity reference field. the added fields show up in the selection, but it won't let me save the reference. here is the error:
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_location_stage_field_key' at row 1: INSERT INTO {field_data_field_location_stage} (entity_type, entity_id, revision_id, bundle, delta, language, field_location_stage_field_key, field_location_stage_entity_type, field_location_stage_entity_id, field_location_stage_revision_id, field_location_stage_language, field_location_stage_delta) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 204 [:db_insert_placeholder_2] => 213 [:db_insert_placeholder_3] => scene [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => field_location_stage_development:0 [:db_insert_placeholder_7] => node [:db_insert_placeholder_8] => 67 [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => [:db_insert_placeholder_11] => ) in field_sql_storage_field_storage_write() (line 448 of *** SERVER *** modules/field/modules/field_sql_storage/field_sql_storage.module).
Comment #17
joachim CreditAttribution: joachim commented> Technically, the titles of the entities you're referencing are [field collection name] [delta]. If you want to show one of the collected fields as the "title" you'll need to do some custom theming
I'm not sure leaving this to individual site theming is enough.
The confirmation message a user sees when they go to delete a collection isn't terribly informative, and doesn't allow the user to understand what it is they're deleting:
I can think of the following ways to address this:
- add admin settings to nominate one field from the field collection as its label
- render the entire FC entity about to be deleted in the confirmation form
Comment #18
kingman1016 CreditAttribution: kingman1016 commentedI think this is related. I'm using dev version and the patch didn't apply, so I couldn't test.
#1617792: Support for entityreference / setting the entity label
Comment #19
hondaman900 CreditAttribution: hondaman900 commented@joachim and #17 above, has anyone found a way to resolve this?
I need to have the user see the name of the FC item they are about to delete in the delete confirmation page. Otherwise they don't know what they are deleting and this causes much grief.
Before I start hacking into this with JQuery I was hoping someone found a solution/workaround.