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

Anonymous’s picture

I have same problem and no solution :-(

RobW’s picture

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 suggest using entity_metadata_wrapper() to get collected field values out of the collection.

Anonymous’s picture

Thanks RobW. I will try it.

annieliu’s picture

Hi, 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!

johnhanley’s picture

I 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"?

RobW’s picture

For 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:

  • Add a "use this field as the field collection item title" radio to FC fields. On save, checks if that field has been filled out, and if so sets it as the FCI title. Otherwise defaults to name-delta.

Better, but more complex:

  • In the field collection field setup, add a "define FCI title with tokens" field that uses available site tokens including the collected field values as title. Would need a dependency on Tokens module, so couldn't be a part of FC proper.

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.

RobW’s picture

Title: Field collection item entity reference » Configurable names of Field collection item entities
Category: support » feature
johnhanley’s picture

Assigned: K1kk0z90 » Unassigned

Hi 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

RobW’s picture

If 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.

annieliu’s picture

Unfortunately Automatic Entity Labels doesn't seem to work with field collections. Would very much like to hear from Bacteria Man on the progress. Thanks.

drupalok’s picture

Unfortunately bacteria man opted out of this, i guess
http://drupal.org/node/1672718#comment-6527292

johnhanley’s picture

Hey 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)

archnode’s picture

I don't think that a field collection item has should 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.

drupalok’s picture

*EDIT * that was rubbish

i will try again...

RobW’s picture

The 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.

drupalok’s picture

@ 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).

joachim’s picture

> 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:

Are you sure you want to delete FIELDNAME 5?

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

kingman1016’s picture

I 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

hondaman900’s picture

Issue summary: View changes

@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.